- (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实现,但无论我制作什么框架,它总是显示相同的红色框架。你觉得我的代码有什么问题吗?
图片:
更新:
嗯,现在我的红色块更高了,但我的第一个tableHeader现在不知何故被隐藏了。第一个是用titleForHeaderInSection实现的。我以为我只是实现了tableHeader height的height,但这并不起作用
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
return 30;
else
return tableView.tableHeaderView.frame.size.height;
}
发布于 2010-03-16 04:10:31
您需要实现此委托方法
- (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
。
https://stackoverflow.com/questions/2450122
复制相似问题