首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >viewForHeaderInSection的帧大小始终相同

viewForHeaderInSection的帧大小始终相同
EN

Stack Overflow用户
提问于 2010-03-16 04:08:42
回答 1查看 21K关注 0票数 18
代码语言:javascript
复制
- (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,但这并不起作用

代码语言:javascript
复制
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
    return 30;
else
    return tableView.tableHeaderView.frame.size.height;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-16 04:10:31

您需要实现此委托方法

代码语言:javascript
复制
    - (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;

在您的例子中,您可以简单地使用return 30;

此外,你正在泄漏view**!**

您的[view release]return之后发生。但是一旦return发生,方法的执行就会中止,您的release就永远不会被调用。

所以你想要这个

代码语言:javascript
复制
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];

去掉下面显式的release

票数 42
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2450122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档