对于IOS,如何在init之后更改节标题?

时间:2015-06-21 09:12:25

标签: ios

首先,我返回你好作为章节标题。我想在单击自定义按钮后将章节标题更改为“hi”?如何切换titleForHeadInsection方法?

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

2 个答案:

答案 0 :(得分:0)

最简单的是重新加载整个表:

[tableView reloadData]

更多优化版本将仅重新加载给定部分,但您可能尚未处于优化阶段。

答案 1 :(得分: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
相关问题