在UITableView标题的标题中添加一个UIButton
问题描述:
我需要在动态填充的UIViewTable上方放置一个按钮。感觉对不填充所述第一小区(行0),而是利用首标区,所以我使用的UITableViewDelegate方法以编程方式创建包含一个UIButton一个UIView:在UITableView标题的标题中添加一个UIButton
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 44)] autorelease]; // x,y,width,height
UIButton *reportButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
reportButton.frame = CGRectMake(80.0, 0, 160.0, 40.0); // x,y,width,height
[reportButton setTitle:@"rep" forState:UIControlStateNormal];
[reportButton addTarget:self
action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchDown];
[headerView addSubview:reportButton];
return headerView;
}
然而,如以下,所描绘的按钮没有被赋予必要的空间(我期望标题的高度符合44的参数)。
这里有什么问题?我应该补充说UITableView是在一个单独的XIB文件中创建的。
答
您是否实施了- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
?
+2
太糟糕了,我只能奖励一个答案。谢谢。 – maralbjo 2010-10-05 19:01:31
不是。谢谢。 – maralbjo 2010-10-05 19:01:01