gpt4 book ai didi

ios - 更新单元格时 UITableView 行分隔符被截断

转载 作者:行者123 更新时间:2023-11-29 01:25:57 26 4
gpt4 key购买 nike

我有一个分组的 UITableView,我在其中的第二部分显示了一些汽车数据。我使用 SDWebImage 从 Web 服务器加载图像.在它的回调中,我调整了图片的大小并更新了我的 ImageView 。

但是,一旦我更新我的 ImageView ,UITableView 分隔符就会被切断。出于说明目的,我给了相应的元素背景颜色当图像尚未加载时,它看起来像这样:

row separator visible

图片更新后是这样的

enter image description here

请注意,即使没有 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com