use*_*180 9 xcode row-height uitableview ios
我有一个带有静态单元格的UITableView,我正在尝试在满足条件时更改单元格的高度.条件正在满足,但细胞高度不会改变.
我正在使用的代码是
[self.tableView setRowHeight:10];
Run Code Online (Sandbox Code Playgroud)
和
self.tableView rowHeight = 10;
Run Code Online (Sandbox Code Playgroud)
这些都不会改变单元格的行高是否还有另一种方法可以改变它们?
Jul*_*per 18
您需要在tableview的.m中实现以下委托方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return customTableCellHeight;
}
Run Code Online (Sandbox Code Playgroud)
然后更改customTableCellHeight的值:
if (condition) {
customTableCellHeight = 80; // or whatever
}
Run Code Online (Sandbox Code Playgroud)
当您的表格单元格高度需要更改时(如条件更改时,您需要调用
[self.tableView reloadData]; //This calls heightForRowAtIndexPath for all cells
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15211 次 |
| 最近记录: |