Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 更改headerView子视图的标题_Iphone_Objective C_Ios_Ipad - Fatal编程技术网

Iphone 更改headerView子视图的标题

Iphone 更改headerView子视图的标题,iphone,objective-c,ios,ipad,Iphone,Objective C,Ios,Ipad,我有以下代码: - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frameWidth, 24.0)]; [header setBackgroundColor:[UIColor grayColor]];

我有以下代码:

- (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];

为什么不起作用?

使用
重新加载节:withRowAnimation

//provide your index for section here
[[self yourTableView]reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
只需
使用
新标题处理这些方法

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

什么是ahkdone?尝试在switchToEditMode:method.上重新加载tableview。它必须是简单的,因为这对我来说很好。我会在
viewForHeaderInSection
中尝试
NSLog(@“%p”,self.editInformationButton)
,然后在尝试更改标题之前再次尝试,并确保您获得相同的地址(即,您处理的是同一个按钮,实例变量在某个点没有重置,等等)。您可以使用它来确认没有重新加载表(即在此期间再次调用了
viewForHeaderInSection
)。