- (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 的实现,但无论我制作什么框架,它总是向我显示相同的红色框架。你看到我的代码有什么问题吗?
Image:
UPDATE:
嗯,现在我的红色块更高了,但我的第一个 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;
.
Also, 你正在泄漏view
!
Your [view release]
发生在return
。但一旦return
发生方法执行被中止并且您的release
从未被调用过。
所以你想要这个
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
并摆脱显式的release
在下面。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)