viewForHeaderInSection的帧总是相同的尺寸
-
20-09-2019 - |
题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if(section != 0) {
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
view.backgroundColor = [UIColor redColor];
return view;
} else {
return tableView.tableHeaderView;
}
}
这是我实现viewForHeaderInSection的但无论帧我让它总是显示我相同的红色框。你看到的任何问题,我的代码?
图像:
更新:
MHM现在我的红色块较高,但我的第一的tableHeader现在以某种方式隐藏。第一个是与titleForHeaderInSection实现。我想我只需要实现的tableHeader高度的高度,但不工作
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
return 30;
else
return tableView.tableHeaderView.frame.size.height;
}
解决方案
您需要实现这个委托方法
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;
在你的情况,你可以简单地return 30;
。
此外,您正在泄漏view
!
您[view release]
的return
后会发生。但是,一旦发生return
执行被中止的方法和你的release
永远不会被调用。
所以,你想这不是
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
和摆脱向下跌破明确release
的。
不隶属于 StackOverflow