更改UITableView节头/页脚WHILE运行应用程序? [英] Change UITableView section header/footer WHILE RUNNING the app?
问题描述
我遇到了一个我无法解决的问题...
我有一个分组表,其分节标题和分节页脚在启动时正确显示,感谢
< pre $ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ - $($)$($)部分
然而,我不知道如何在稍后更新它们,我不知道如何改变这些文本,这是相当令人沮丧的,因为在我看来,它不应该比改变文本标签或任何东西更难...(一些.text属性...)
我搜索了所有文档,但没有运气...
任何帮助都非常有效,非常感谢!
Regards,
Enrico
在委托方法中,添加一个方法调用, ,例如:
$ $ p $ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
switch(section){
case firstSectionTag:
return [self firstSectionTitle];
case secondSectionTag:
return [self secondSectionTitle];
// ...
默认值:
return nil;
}
}
- (NSString *)firstSectionTitle {
//以编程方式生成第一部分标题,例如return [[NSDate date] description];
}
// ...
然后,当您需要更新部分标题,发送触发类似以下方法的 NSNotification
:
- (void)refreshTableSectionTitles:(NSNotification *)notification {
[tableView reloadData];
$ b如果表格很大并且想要更精细的控制,可以传递一个 NSNotification
与 NSDictionary
包含您要重新加载的部分,请阅读 -refreshTableSectionTitles code>取回 NSInteger
部分,并使用表视图的 -reloadSections:withRowAnimation:
重新加载该特定部分。
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
and
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
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
解决方案 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];"
}
// ...
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];
}
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节头/页脚WHILE运行应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!