ios - 尝试在heightForRowAtIndexPath之后设置cellForRowAtIndexPath中单元格的高度

标签 ios objective-c uitableview heightforrowatindexpath

由于heightForRowAtIndexPathcellForRowAtIndexPath之前被调用,所以我假设如果我想在cellForRowAtIndexPath内修改高度,则可以这样做。看来我做不到。我已经通过NSLog进行了测试,如果更改了cell.frame.size.height,更改将正确存储在其中,但是单元格本身不会采用新的大小(它使用的是我在heightForRowAtIndexPath中设置的大小)。

还有另一种方法可以调整在cellForRowAtIndexPath之后某个时刻调用的单元格的高度吗?如果没有,还有其他解决方法吗?我需要使用cellForRowAtIndexPath,因为我正在动态决定是否要依次将图像随机添加到每个单元格中。

最佳答案

您应该在heightForRowAtIndexPath方法中放入随机决定添加图像的代码。

使用NSMutableDictionary跟踪使用图像的NSIndexPath

关于ios - 尝试在heightForRowAtIndexPath之后设置cellForRowAtIndexPath中单元格的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15140405/

相关文章:

ios - 无法从 podfile 更新 firebase 最新框架

objective-c - 如何继承 UIScrollView 并将委托(delegate)属性设为私有(private)

ios - iOS 中的新闻提要检索

objective-c - 在 Cocoa 和 Cocoa Touch 中使用 int 是错误的吗?

纯 c/posix 风格的 iPhone 文件 IO

Swift - UITableViewCell?不可转换为 UITableViewCell

ios - Apple Watch Table 上的行选择崩溃

objective-c - Objective C - 可以通过触摸 ImageView 或 Image 来触发 Segue 吗?

ios - 如何将 UITableViewCell 对齐到 UITableView 的底部?

ios - UITableView 中批量行插入/删除的顺序是什么?