我创建了一个新的 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/