0
子視圖的頭銜,我有以下代碼:改變headerView
- (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];
爲什麼這不工作嗎?
什麼是AHConstants kDone? – Vishal
嘗試重新加載switchToEditMode上的tableview:方法.. –
它必須是簡單的東西,因爲這對我來說工作正常。我會在'viewForHeaderInSection'中嘗試'NSLog(@「%p」,self.editInformationButton_)',然後在嘗試更改標題之前再次嘗試,並確保獲得相同的地址(即,您正在處理同一個按鈕,實例變量在某個時刻沒有被重置,等等)。你可以使用它來確認表沒有被重新加載(即在此期間再次調用'viewForHeaderInSection')。 – Rob