ios - 未调用 headerViewForSection

标签 ios uitableview delegates

我创建了一个新的 Storyboard 应用程序,为我的表创建了一个 IBOutlet,实现了两个表委托(delegate)。

@interface FirstViewController () <UITableViewDelegate,UITableViewDataSource>.

我还实现了可选选择器“headerViewForSection”:
- (UITableViewHeaderFooterView *)headerViewForSection:(NSInteger)section
{
    NSLog(@"called");
    //UITableViewHeaderFooterView* header =[self.testTable headerViewForSection:0];
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    label.text = @"toast";
    label.font = [UIFont fontWithName:@"Arial" size:6];
    //[header addSubview:label];
    return label;
}

不幸的是,我从来没有在控制台中得到“调用”。我也尝试手动调用它,但没有成功。

为什么没有调用该函数?

P.S,我在构造函数中添加了:
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    _testTable.delegate = self;
    _testTable.dataSource = self;
}

所以我指定了委托(delegate),我不知道为什么它不起作用。

最佳答案

该方法是 UITableView 的一部分并且是 UIViewController 的内部方法不需要去附近的任何地方。

我相信你正在寻找的是方法......
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
这是 UITableViewDelegate 的一部分.

关于ios - 未调用 headerViewForSection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18897001/

相关文章:

ios - 使用 Swift 比较类型

iphone - 如何创建自定义 UIViewController 过渡动画?

ios - UIProgressView 约束问题

没有 MainMenu.xib 的 Cocoa 应用程序

ios - Google Analytics 无法与 GTM 和 Firebase iOS 配合使用

iOS:一段时间后保存托管对象上下文需要超过 1 秒

ios - 如何将 json 子值显示到 uitableview 中的单独部分?

iphone - 为 UITableView 创建节索引标题的性能问题

iphone - 在 Controller 之间传递 UISegmentedControl 值...

iphone - 委托(delegate)方法不工作 ios