我想使用此函数扩展UITableViewCell,从didSelectRowAtIndexPath调用:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(selectedCellIndexPath != nil &&
[selectedCellIndexPath compare:indexPath] == NSOrderedSame)
return 128;
return 43;
}
单击一个单元格会展开它,单击另一个单元格将折叠为旧单元格并展开新单元格。到现在为止还挺好。但是当我点击一个扩展的单元格时,我也想要折叠单元格,而不知道怎么做?
作为奖励:显示未扩展单元格的内容,与下面的单元格重叠。如何防止显示应按折叠单元格大小裁剪的内容?
答案 0 :(得分:0)
如果didSelectRowAtIndexPath:…
等于indexPath
,您只需登记selectedCellIndexPath
,然后将selectedCellIndexPath
设为nil
。
您没有提供该代码,所以我只是在猜测。
答案 1 :(得分:0)
您还可以使用标题中声明的BOOL,然后使用
中的int-didSelectRowAtIndexPath:indexPath {
if(your condition) {
BOOL Selected = YES
[tableView reloadRowAtIndexPath:indexPath]
}
}
并在
-heightForRowAtIndexPath:indexPath {
if(indexPath.Section == TheOneYouWant && indexPath.row == TheOneYouWant && Selected)
return YourHeight;
else if (indexPath.Section == TheOneYouWant && indexPath.row == TheOneYouWant && !Selected)
return yourOtherHeight;
}