如何刷新viewForFooterInSection

发布于 2024-11-02 10:50:19 字数 1984 浏览 2 评论 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;  
}  

在这里,我尝试在视图的页脚部分添加按钮,并且按钮包含文本为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆依然 2024-11-09 10:50:19

您的“更新:”方法将接收作为发送者的按钮。
Sender 应该是一个 id 对象,然后您可以将其转换为 UIButton * 并根据需要更新其文本,如下所示:

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

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文