1

我有一个UITableViewCell基于文本内容的动态高度。在tableview:heightForRowAtIndexPath:高度被计算。这很好用。

当单元格使用editingStyle进入编辑模式时,UITableViewCellEditingStyleDelete它会稍微缩进单元格并且可以将内容推出一些导致rowHeight改变的内容。同样,这很好用,因为将 tableview 切换到编辑会导致 table 重新布局,因此 rowHeight 被重新计算。

当您单击红色按钮或滑动单元格时,单元格右侧会出现一个删除按钮。然而,这不会触发表格的重新布局,只会触发单元格本身。这里的问题是,如果内容超出底部边缘,则单元格不会调整大小。

当删除按钮出现时,有没有办法触发表格的重新布局?

4

1 回答 1

1

一般来说,高度UITableViewCell只能通过 设置tableview:heightForRowAtIndexPath:,而后一种方法在 之前只能调用一次(每行每节)tableView:cellForRowAtIndexPath:,因此[tableview reloadData]如果要调整 UITableViewCell 高度,则必须进行调整。

也许你可以在这些委托方法中做点什么

// The willBegin/didEnd methods are called whenever the 'editing' property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row
- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath; 

- (void)layoutSubviews对于您的问题,您可以在自定义 UITableViewCell 中重置文本控件的属性。

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat theWidth = self.frame.size.height; //changed when entering the edit style
    ...
}

希望这些对您有所帮助。

于 2013-04-26T06:03:24.910 回答