我试图让我的一些细胞更高 . 我试过用
CGRect rect = cell.frame;
NSLog(@"before height: %f",rect.size.height);
rect.size.height +=20;
cell.frame = rect;
NSLog(@"AFTER height: %f",cell.frame.size.height);
在
cellForRowAtIndexPath
和
willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
日志显示值已更改但未显示模拟器中的任何更改 .
谢谢您的帮助
3 回答
使用
tableView:heightForRowAtIndexPath
方法 .Apple文档清楚地解释了该做什么 . UITableView class reference
每个tableView都有一个委托属性 . 将它设置到viewController并实现上面的方法 . 它的签名是
因此,根据 indexPath ,返回您想要的任何高度 .
如果要为所有行保持恒定高度,可以使用
UITableView
的rowHeight
属性 .使用UITableViewDelegate的
heightForRowAtIndexPath
. 例:要使某些单元格更大,您应该实现方法
tableView:heightForRowAtIndexPath:
tableView:cellForRowAtIndexPath:
用于配置tableView需要显示的单元格的内容 .请注意,如果您有一个非常大的表(1000个条目),
tableView:heightForRowAtIndexPath:
会对性能产生影响,当表视图显示时,会在每一行调用此方法 .