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

标签 ios objective-c iphone swift uitableview

我有一个分组的 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/

相关文章:

ios - 滚动时表格 View 不响应触摸

ios - Objective C 如何为 AVPlayer 提供多种文件路径可能性

ios - XCode & Instruments,如何清除进程列表

ios - 如何通过 ImagePickerViewController 获取录制视频的 Assets url?

iPhone - 动态改变颜色

ios - 快速显示和隐藏 CALayer 的速度似乎很慢

ios - 从 nsbundle 访问图像

objective-c - 向类(class)发送消息 - 摆脱 "multiple methods named [...]"警告

ios - 以时间间隔执行选择器

iphone - 将 NSDictionary 保存到 NSUserDefaults