如何刷新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"->例如"Update:4.30 PM"
所以用户会理解他上次更新的时间,但是现在当我按下这个按钮时,更新已经完成了,但是我想更新(刷新)按钮的文本,例如,如果我在15分钟后按下按钮,它应该显示"更新:下午4:45"…如何刷新此文本

非常感谢

你的"update:"方法将接收按钮作为发送者。Sender应该是一个id对象,然后你可以将它强制转换为UIButton *,并像这样更新它的文本:

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

相关内容

  • 没有找到相关文章