【发布时间】:2014-11-19 14:38:27
【问题描述】:
我正在尝试向 UITableView 添加页脚。该表是一个 cmets 表,页脚是用户输入他/她的 cmets 以进行发布的位置。所以很自然,我定义了一个 UIView 并在 UIView 内部添加了一个 UITextField 和一个 UIButton。 (左到右)。
问题是 UIView 不包含子视图。我希望孩子们在父页脚内垂直居中。我的代码如下。我究竟做错了什么?现在父视图显示为红色的薄板。与父级重叠的是高度大于父级的 UITextField 和 UIButon。
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
static UIView *footer =nil;
if (nil == footer) {
footer =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 70)];
footer.backgroundColor=[UIColor redColor];
self.commentInputTextView=[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 240, 50)];
self.commentInputTextView.delegate=self;
self.commentInputTextView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.commentInputTextView.backgroundColor=[UIColor greenColor];
[footer addSubview:self.commentInputTextView];
UIButton *post = [[UIButton alloc] initWithFrame:CGRectMake(250, 0, 60, 50)];
post.backgroundColor=[UIColor blueColor];
[post setTitle:@"Post" forState:UIControlStateNormal];
[footer addSubview:post];
[footer sizeToFit];
}
return footer;
}
【问题讨论】:
标签: ios uitableview uiview footer addsubview