2015-06-21 43 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