how to refresh viewForFooterInSection
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if(footerView == nil) {
//allocate the view if it doesn't exist yet
footerView = [[UIView alloc] init];
UIImage *imag开发者_如何学JAVAe = [[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;
}
here i am trying to add button in footer section of view and button contain text as "Update:currentTime"-> e.g."Update:4.30 PM"
so user will understand when he did last update but now when i am pressing this button update is done in view but i want to update(refresh) text of button too e.g if i press button after 15 minutes the it sould show "Update:4:45 PM"...how to refresh this textthank you very much
Your "update:" method will receive the button as the sender. Sender should be as an id object, you can then cast it to a UIButton * and update its text as you want like this :
void update:(id)sender {
[(UIButton)*sender setTitle:@"NEW TEXT" forState:UIControlStateNormal];
//rest of your update code
}
精彩评论