如何刷新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 *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;
}
在这里,我尝试在视图的页脚部分添加按钮,并且按钮包含文本为“Update:currentTime”->例如“更新:4.30 PM”
所以用户会明白他上次更新的时间,但现在当我按下此按钮时,更新已在视图中完成,但我也想更新(刷新)按钮的文本,例如,如果我在 15 分钟后按下按钮,它会显示“更新:4” :45 PM"...如何刷新此文本
非常感谢
- (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;
}
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 text
thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的“更新:”方法将接收作为发送者的按钮。
Sender 应该是一个 id 对象,然后您可以将其转换为 UIButton * 并根据需要更新其文本,如下所示:
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 :