一:改变它的加载顺序,或者说白了就是计算好cell高度后,再次让它加载heightForRowAtIndexPath方法;
二:直接在heightForRowAtIndexPath计算,做判断,直接返嫌梁回对应的高度。
以下老燃是第一种方法的实例:
U
ITableView设置单元格的高度的方法
- (CGFloat)tableView:(UITableView
// Somewhere in your header:
NSIndexPath *selectedCellIndexPath;
// And in the implementation file:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedCellIndexPath = indexPath;
// Forces the table view to call heightForRowAtIndexPath
[tableView reloadRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// Note: Some operations like calling [tableView cellForRowAtIndexPath:indexPath]
// will call heightForRow and thus create a stack overflow
if(selectedCellIndexPath != nil
&& [selectedCellIndexPath compare:indexPath] == NSOrderedSame)
return 128;return 64;}reloadRowsAtIndexPaths方法将重新调用heightForRowAtIndexPath使单元侍者虚格改变高度。