gpt4 book ai didi

ios - heightForHeaderInSection 没有被调用?

转载 作者:可可西里 更新时间:2023-11-01 03:37:20 24 4
gpt4 key购买 nike

我想更改tableHeader 的高度、字体等...

我实现了 UITableViewDelegateUITableViewDataSource 并添加了 heightForHeaderInSectionviewForHeaderInSection。但是这两种方法都没有被调用。 numberOfRowsInSection/cellForRowAtIndexPath 等其他方法工作正常。我可以看到表格,但没有标题 :(

有什么想法吗?

代码如下:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.poHeader.itemList count];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
NSLog(@"*******height");
return 44.0;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

NSLog(@"***in viewForHeader In section");

UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(2, 166, 300.0, 44.0)];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont systemFontOfSize:13];
headerLabel.frame = CGRectMake(2, 166, 300.0, 44.0);

headerLabel.text = @"Part No. Description Ext Cost"; // i.e. array element
[customView addSubview:headerLabel];

return customView;
}

最佳答案

差不多一年过去了,但我猜你只设置了数据源而没有设置委托(delegate)?

你必须在你的 Controller 中有这样的东西:

myTableview.delegate = self;
myTableview.dataSource = self;

您提到正在调用 numberOfRowsInSection/cellForRowAtIndexPath。两者都属于 UITableViewDataSource 而不是 UITableViewDelegate

关于ios - heightForHeaderInSection 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8839316/

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