简体   繁体   English

更改UITableView自定义标题视图的按钮图像不起作用

[英]Change UITableView custom header view's button image not working

I created a UIView using nib file. 我使用nib文件创建了一个UIView。 and set it as table view header view. 并将其设置为表格视图标题视图。 In this view I have a button. 在此视图中,我有一个按钮。 I tried to change the button's image, but nothing changes. 我试图更改按钮的图像,但是没有任何变化。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        HealthPlanHeaderView *view = (HealthPlanHeaderView *)[[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([HealthPlanHeaderView class]) owner:self options:nil] firstObject];
        [view.addButton addTarget:self action:@selector(editFood) forControlEvents:UIControlEventTouchUpInside];
        self.healthPlanHeaderView = view;
        return view;
    }else {
        return nil;
    }
}

- (void)editFood {
    self.healthEditing = !self.healthEditing;
    UIImage *image = self.healthEditing ? [UIImage imageNamed:@"finish"] : [UIImage imageNamed:@"edit-button"];
    [self.healthPlanHeaderView.addButton setImage:image forState:UIControlStateNormal];
}

I noticed the button image did set, but the button won't show newly set image, it remains unchanged. 我注意到按钮图像已设置,但是按钮不会显示新设置的图像,它保持不变。

也许,您只需要调用tableView的reloadData来刷新它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM