Enr*_*rci 21 iphone header title footer uitableview
我遇到了一个我无法解决的问题...我有一个分组表,其部分标题和部分页脚在启动时正确显示感谢
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
和
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
然而,我无法弄清楚如何更新它们,我不知道如何更改这些文本,这是非常令人沮丧的,因为在我看来,它必须没有比改变文本标签或其他任何东西更难......(一些".text"属性......)
我搜索了整个文档,没有运气......
任何帮助都非常受到赞赏!此致,恩里科
Ale*_*lds 25
在委托方法中,添加一个返回节名称的方法调用,例如:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch (section) {
case firstSectionTag:
return [self firstSectionTitle];
case secondSectionTag:
return [self secondSectionTitle];
// ...
default:
return nil;
}
}
- (NSString *)firstSectionTitle {
// generate first section title programmatically, e.g. "return [[NSDate date] description];"
}
// ...
Run Code Online (Sandbox Code Playgroud)
然后,当您需要更新节标题时,发送一个NSNotification
触发器,如下面的方法:
- (void)refreshTableSectionTitles:(NSNotification *)notification {
[tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
如果表很大,你想更好地控制,传递一个NSNotification
与NSDictionary
包含要重新加载部分,读取字典中-refreshTableSectionTitles
找回部分NSInteger
,并使用表格视图的-reloadSections:withRowAnimation:
重新加载特定部分.
您可以使用:
-(void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
Run Code Online (Sandbox Code Playgroud)
并在
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
在语句中定义新的标题文本.
这将在更改页眉/页脚时创建一个漂亮的动画.