在运行应用程序时更改 UITableView 部分页眉/页脚? [英] Change UITableView section header/footer WHILE RUNNING the app?
问题描述
我遇到了一个我无法解决的问题...我有一个分组表,其部分页眉和部分页脚在启动时正确显示,这要归功于
I'm facing a problem I cannot resolve... I have a grouped table whose section header and section footer get displayed correctly upon launch thanks to
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
和
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
但是,我不知道以后如何更新它们,我不知道如何更改这些文本,这很令人沮丧,因为在我看来,这比更改文本标签或其他任何事情都要难..(一些.text"属性...)
Yet, I can't figure out how to update them later, I don't know how to change those texts and it's quite frustrating because in my mind it had to be nothing harder than changing a text label or whatever... (some ".text" property...)
我搜索了所有文档都没有运气......
I searched all through the documentation with no luck...
任何帮助都非常重要&感激不尽!问候,恩里科
Any help is highly & kindly appreciated! Regards, Enrico
推荐答案
在delegate方法中,添加一个返回section名称的方法调用,例如:
In the delegate method, add a method call that returns the section name, e.g.:
- (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];"
}
// ...
然后,当您需要更新部分标题时,发送一个 NSNotification
触发类似以下方法的内容:
Then, when you need to update the section title, send an NSNotification
that triggers something like the following method:
- (void)refreshTableSectionTitles:(NSNotification *)notification {
[tableView reloadData];
}
如果表很大并且你想要更好的控制,传递一个 NSNotification
和一个包含你想要重新加载的部分的 NSDictionary
,阅读 中的字典-refreshTableSectionTitles
取回 NSInteger
部分,并使用表格视图的 -reloadSections:withRowAnimation:
重新加载该特定部分.
If the table is large and you want finer control, pass an NSNotification
with an NSDictionary
that contains the section you want to reload, read the dictionary in -refreshTableSectionTitles
to get back the section NSInteger
, and use the table view's -reloadSections:withRowAnimation:
to reload that specific section.
这篇关于在运行应用程序时更改 UITableView 部分页眉/页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!