I have a UITableView which its cells may vary depending on the data to be shown on each, so I have two reusable cells, the UIPendingXOCell
and the UIXOCell
. At some point, every UIPendingXOCell
becomes a UIXOCell
.
See the code below for a bit of context:
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
}
}
Example: I have a list of 5 objects, which when calling .reloadData()
generates 1 UIPendingXOCell
and 4 UIXOCell
(all fine). I also have an action running on the background which changes the objects in a way that when I call .reloadData()
again, they all become UIXOCell
(all fine again, cellForRowAtIndexPath
is being called and falling into the else
block).
My problem is that it takes about 10 seconds after cellForRowAtIndexPath
is called for the cell to be rendered as a UIXOCell
rather than a UIPendingXOCell
.
Has anyone had this problem before? If so, how should I fix it?
Thanks!
Sound like you are not calling reloadData
from main thread (UI thread). Make sure you are updating UI from main thread.
dispatch_async(dispatch_get_main_queue()) {
tableView.reloadData()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With