Ios 如何将UITableView静态单元格设置为自定义高度?
我有一个静态单元格的UITableView,我试图在单元格满足条件时更改单元格的高度。条件已满足,但电池高度不会改变 我使用的代码是Ios 如何将UITableView静态单元格设置为自定义高度?,ios,xcode,uitableview,row-height,Ios,Xcode,Uitableview,Row Height,我有一个静态单元格的UITableView,我试图在单元格满足条件时更改单元格的高度。条件已满足,但电池高度不会改变 我使用的代码是 [self.tableView setRowHeight:10]; 及 这两项都不会更改单元格的行高 是否有其他方法可以更改它们?您需要在tableview的.m中实现以下委托方法: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)index
[self.tableView setRowHeight:10];
及
这两项都不会更改单元格的行高
是否有其他方法可以更改它们?您需要在tableview的.m中实现以下委托方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return customTableCellHeight;
}
然后更改customTableCellHeight的值:
if (condition) {
customTableCellHeight = 80; // or whatever
}
当表格单元格高度需要更改时(如条件更改时),需要调用
[self.tableView reloadData]; //This calls heightForRowAtIndexPath for all cells
您可以将其用于tableview的所有行
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 100
}
可以创建具有文本高度的动态单元格,然后可以在“表”视图中同时设置静态和动态单元格 这里是链接到动态单元格的文本
它的可能副本不需要调用
reloadData
。当条件改变时,您需要调用reloadData,而不是在heightforrowatinexpath内部,而是在它外部。这将导致重新计算高度,并允许动态调整单元格大小。
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 100
}