我需要在动态填充的 UIViewTable 的正上方放置一个按钮。不填充第一个单元格(第 0 行),而是利用标题区域感觉是正确的,因此我使用 UITableViewDelegate 方法以编程方式创建一个包含 UIButton 的 UIView:
- (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 文件中创建的。
你还必须实施tableView:heightForHeaderInSection: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006942-CH3-SW6在你的表视图委托上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)