0

我有以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frameWidth, 24.0)];
    [header setBackgroundColor:[UIColor grayColor]];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, self.view.frameWidth - 100, header.frameHeight)];
    label.backgroundColor= [UIColor grayColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont boldSystemFontOfSize:17.0];

    [header addSubview:label];
    if (section == kEditInformationSection){
        label.text = [AHConstants kEditInformation];

        UIButton *editInformationButton = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frameWidth - 50, 0, 50, header.frameHeight)];
        [editInformationButton setTag:1000];
        [editInformationButton setBackgroundColor:[UIColor grayColor]];
        [editInformationButton setTitle:[AHConstants kEdit] forState:UIControlStateNormal];
        [editInformationButton addTarget:self action:@selector(switchToEditMode:) forControlEvents:UIControlEventTouchUpInside];
        self.editInformationButton_ = editInformationButton;
        [header addSubview:self.editInformationButton_];
        self.tableHeaderView_ = header;
        return self.tableHeaderView_;
    } else if (section == kNotificationIntervalInfo){
         label.text = [AHConstants kNotificationInterval];
        return header;
    }

    return nil;
}

在按钮操作上,我想更改按钮标题,所以我做了以下操作:

[self.editInformationButton_ setTitle:[AHConstants kDone] forState:UIControlStateNormal];

为什么这不起作用?

4

1 回答 1

0

采用reloadSections:withRowAnimation

//provide your index for section here
[[self yourTableView]reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

只是handle这些方法new title

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
于 2013-01-07T07:00:22.850 回答