In iOS, are there any potential pitfalls to reloading a UITableView that is not currently being displayed?
I have found that I had some very peculiar bugs where cell content was disappearing but it only seemed to happen when I had switched to another Tab.. (the UIViewController with tableView on the first tab is still in memory and responding to external API updates)
so the line:
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: row, inSection: 0)], withRowAnimation: UITableViewRowAnimation.None)
}
is executing code to modify the display of a table that is not actually being displayed and this is when the bug was happening.
if I added some code to the viewControllers ViewDidAppear and ViewDidDisappear to basically block updates to the tableView (and then do a full refresh when re-entering that viewController) it seemed to solve the problem.
dispatch_async(dispatch_get_main_queue(), {
if self.delegate.viewIsDisplayed() {
self.tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: row, inSection: 0)], withRowAnimation: UITableViewRowAnimation.None)
}
}
I do not know why the problem was happening and was hoping someone might be able to shine some light on what I was observing before (cells randomly clearing content and then re-appearing on each subsequent reload)
reloadRowsAtIndexPaths() always attempts some form of animation, .None just tells it to use the default animations (see docs). This might be messing with your cell's content of the tableView is not visible.
If the tableView is offscreen try reloadData or manually retrieving the cell using cellForRowAtIndexPath to edit it's contents.
The documentation suggests the later if the user doesn't need to have any indication that the contents have changed.
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