Axe*_*xel 2 iphone uitableview ios
我尝试设置一个tableView.我在所有部分的行中使用标准单元格,除了最后一部分(包含一行).因此,除了特殊的部分之外,我还想对所有这些部分使用标准布局.
下面是一个简短的例子,我的"特殊"单元格在第3节(只有一行):
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 3)
return 5;
return **????**;
}
Run Code Online (Sandbox Code Playgroud)
在??? 我想返回从UITableView计算的宽度(就像我没有实现该方法).
[super self:tableView heightForHeaderInSection:(NSInteger)section];
不起作用.我知道我可以访问
[tableView setionHeaderHeight]
Run Code Online (Sandbox Code Playgroud)
这默认为10,显然没有考虑到我有其他部分的章节标题,这将需要额外的空间.我试过了,但它会让这些部分过于接近(见截图):
(注意:我感兴趣的部分是一个看起来不像单元格的部分:带有日期的部分(不可见的背景)).

因此,最简单的方法是将布局移交给完美的标准实现 - 除了section3.
我有什么选择?
以防万一:在iOS 5中引入了一个新常量,称为UITableViewAutomaticDimension.正如文档所说,当您想UITableView使用默认值时,应该从委托方法返回它.
那么,你的案例的代码是:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 3) {
return 5;
} else {
return UITableViewAutomaticDimension;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1402 次 |
| 最近记录: |