UITableView - cellForRowAtIndexPath延迟渲染

Mar*_*rte 4 objective-c uitableview ios swift

我有一个UITableView,它的单元格可能会根据每个上面显示的数据而有所不同,所以我有两个可重复使用的单元格,UIPendingXOCellUIXOCell.在某些时候,每UIPendingXOCell一个都成为一个UIXOCell.

有关上下文,请参阅下面的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var xoItem = self.xoForIndexPath(indexPath)
        var xoItemPFObject = xoItem.pfObject

        // If it's a pending XO
        if xoItemPFObject.objectId == nil {
            var cellIdentifier = "cell-pending-xo-list"
            var cell: UIPendingXOCell! = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as UIPendingXOCell!

            ...

            return cell
        }
        else {
            var cellIdentifier = "cell-xo-list"
            var cell: UIXOCell! = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as UIXOCell!

            ...

            return cell
        }
    }
Run Code Online (Sandbox Code Playgroud)

示例:我有一个包含5个对象的列表,在调用时.reloadData()生成1 UIPendingXOCell和4 UIXOCell(全部正常).我还有一个在后台运行的动作,它以一种方式改变对象,当我.reloadData()再次调用它们时,它们都变成了UIXOCell(一切都很好,cellForRowAtIndexPath被调用并落入else块中).

我的问题是,cellForRowAtIndexPath调用单元格后需要大约10秒才能将其渲染为a UIXOCell而不是a UIPendingXOCell.

以前有人有这个问题吗?如果是这样,我该如何解决?

谢谢!

Kir*_*ins 10

听起来好像你没有reloadData从主线程(UI线程)调用.确保从主线程更新UI.

dispatch_async(dispatch_get_main_queue()) { 
    tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)