2011-04-21 96 views
0
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 

    if(footerView == nil) { 
     //allocate the view if it doesn't exist yet 
     footerView = [[UIView alloc] init]; 


     UIImage *image = [[UIImage imageNamed:@"update.png"] 
          stretchableImageWithLeftCapWidth:8 topCapHeight:8]; 

     //create the button 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     [button setBackgroundImage:image forState:UIControlStateNormal]; 

     //the button should be as big as a table view cell 
     [button setFrame:CGRectMake(100, 3, 300, 50)]; 

     NSDate *today = [NSDate date]; 
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
     // display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings 
     [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; 
     NSString *currentTime = [dateFormatter stringFromDate:today]; 


     [dateFormatter release]; 
     NSLog(@"User's current time in their preference format:%@",currentTime); 

     NSString *btnString; 


     NSDate* now = [NSDate date]; 
       btnString = [NSString stringWithFormat:@"%@:%@",@"Update",currentTime];  


     //set title, font size and font color 
     [button setTitle:btnString forState:UIControlStateNormal]; 
     [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]]; 
     [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 

     //set action of the button 
     [button addTarget:self action:@selector(update:) 
     forControlEvents:UIControlEventTouchUpInside]; 

     [footerView addSubview:button]; 

    } 
    return footerView; 
} 

在這裏,我想在視圖按鈕包含文本頁腳部分添加按鈕「更新:currentTime的」 - >如「更新:下午4:30」
所以當他沒有用戶會明白最後更新,但現在當我按下這個按鈕更新在視圖中完成,但我想更新(刷新)按鈕的文本,例如,如果我按下按鈕15分鐘後,它應該顯示「更新:4:45 PM」...如何刷新本文如何刷新viewForFooterInSection

非常感謝你

回答

3

您的「更新」方法將接收按鈕作爲發件人。 發件人應作爲ID的對象,那麼你可以將它轉換爲一個UIButton *,當你想這樣的更新它的文本:

void update:(id)sender {  
[(UIButton)*sender setTitle:@"NEW TEXT" forState:UIControlStateNormal]; 
//rest of your update code 
} 
+0

非常感謝你......我學到了很多東西從這個論壇和類似ü幫助人們再次感謝 – Pooja 2011-04-21 16:15:21

+0

不客氣,我從stackoverflow也學到了很多東西,只是儘可能地回饋。妥善保管好代碼:) – mbritto 2011-04-26 12:53:58