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
)。