我有一个分组的 UITableView,我在其中的第二部分显示了一些汽车数据。我使用 SDWebImage 从 Web 服务器加载图像.在它的回调中,我调整了图片的大小并更新了我的 ImageView 。
但是,一旦我更新我的 ImageView ,UITableView 分隔符就会被切断。 出于说明目的,我给了相应的元素背景颜色 当图像尚未加载时,它看起来像这样:
图片更新后是这样的
请注意,即使没有 subview (UIImageView
)隐藏它,行分隔符也会以某种方式在 UITableView 单元格之间被切断。
根据 UITableView
部分,行高会有所不同,因此我覆盖了 heightForRowAtIndexPath
UITableView 委托(delegate)
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == 0 {
return GFFloat(44)
}
else {
return CGFloat(220)
}
}
谁能告诉我为什么分隔符消失了,我该如何解决这个问题?我读过有关在更新图像时重新加载下一个 UITableViewCell
的内容,但由于我显示了很多汽车,所以当我尝试此操作时我的应用程序崩溃了。
最佳答案
只需添加以下方法即可解决分隔符问题。
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if cell.respondsToSelector("setSeparatorInset:") {
cell.separatorInset = UIEdgeInsetsZero
}
if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
cell.preservesSuperviewLayoutMargins = false
}
if cell.respondsToSelector("setLayoutMargins:") {
cell.layoutMargins = UIEdgeInsetsZero
}
}
关于ios - 更新单元格时 UITableView 行分隔符被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34018874/