2015-06-21 21 views
0

首先,我將hello作爲章節標題返回。我想在單擊自定義按鈕後將章節標題更改爲「hi」?如何切換titleForHeadInsection方法?對於IOS,如何在init之後更改節標題?

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    return @"hello"; 
} 
+1

這可能會幫助你http://stackoverflow.com/questions/19350124/uitableview-section-header-how-to-change-text –

+0

或本:HTTP:/ /stackoverflow.com/questions/4346944 – luk2302

回答

0

簡單的方法是重新加載整個表:

[tableView reloadData] 

更優化的版本將只重新加載一個給定的部分,但你可能不會在尚未優化的階段。

+0

hhhhhh ...。我真的想採取優化方法......因爲我的項目有很多插入行和刪除行選項......我只是通過一個簡單的例子來問這個問題 – seguedestination

0

存放在屬性節的標題在你UIViewController,或任何類作爲您的UITableViewDelegate

@property (nonatomic,strong) NSString *sectionTitle; 

並將其值設置爲@"hello"的某處。 然後當你在你的按鈕按下方法,更新self.sectionTitle與新標題。

self.sectionTitle = @"hi"; 

然後重新加載您的整個UITableView或重新加載適當的部分。

[tableView reloadData]; // Entire 

或者

NSIndexSet *sectionIndex = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];          
[self.tableView reloadSections:section withRowAnimation: UITableViewRowAnimationAutomatic]; 
// Specific section 
相關問題