UITableView - deferred rendering cellForRowAtIndexPath

I have a UITableView, which its cells can change depending on the data that will be displayed on each, so I have two reusable cells, UIPendingXOCelland UIXOCell. At some point, everyone UIPendingXOCellbecomes UIXOCell.

See the code below for a little context:

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

        // If it 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
        }
    }

Example: I have a list of 5 objects that, when called, .reloadData()generate 1 UIPendingXOCelland 4 UIXOCell(everything is fine). I also have an action performed on the background that changes objects in such a way that when .reloadData()they are called again, they all become UIXOCell(everything is fine again, cellForRowAtIndexPathit gets called and gets into the block else).

, 10 cellForRowAtIndexPath UIXOCell, UIPendingXOCell.

- ? , ?

!

+4
1

, reloadData ( ). , .

dispatch_async(dispatch_get_main_queue()) { 
    tableView.reloadData()
}
+10

All Articles