gpt4 book ai didi

ios - 如何覆盖 tableView :titleForHeaderInSection: to adjust section headers of static UITableViews?

转载 作者:行者123 更新时间:2023-12-01 16:00:42 25 4
gpt4 key购买 nike

我正在玩 Storyboard,我为一个 Controller 设置了 UITableView由两个部分组成。在这两个部分中,我添加了几个 静态 细胞。
但是,根据代码路径,我想显示不同的 标题 对于我的两个部分。
由于没有来源和委托(delegate),我应该如何覆盖 tableView:titleForHeaderInSection: ?

最佳答案

使用静态 TableView ,您仍然可以(并且必须)将数据源连接到 UITableViewController。关键是,如果您实现数据源方法,那么这将覆盖您在表格 View 中设置的静态内容。您可以毫无问题地覆盖 titleForHeader,因为这是您想要做的。

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0)
return @"HELLO!";
else {
return [super tableView:tableView titleForHeaderInSection:section];
}
}

将静态表中第 0 部分的标题设置为 HELLO!,覆盖在 xib 中设置的标题。其他的则保留在 xib 中。

关键是静态表的填充方式与动态表完全相同,只是 UITableViewController 实现了所有数据源方法的自己的版本。这些方法大概会从 xib 文件中读取信息并将适当的信息发送回 TableView 。如果您想要静态内容,请不要实现或调用 super。如果您想要自己的内容,请使用与上述类似的代码。

关于ios - 如何覆盖 tableView :titleForHeaderInSection: to adjust section headers of static UITableViews?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com