Currently, I have my app hitting my endpoints, and getting back 10 or less items. In the event the items returned is less than 10, and the UITableView
is already showing 10 items, reloadData()
will cause an error because the size is not the same as it was last time. Right now, when I get my response all I do is:
tableView.beginUpdates()
self.items = items //where self.items is the array that backs the UITableView, and items are the items I got back in form of JSON from the server.
tableView.reloadData()
tableView.endUpdates()
Why will it cause error? If you are using tableView.reloadData(), you don't need to call endUpdates() and beginUpdates(). Just simply assign the items and reload tableView data.
self.items = items tableView.reloadData()
If you are on the background thread call the above code on the main queue.
dispatch_async(dispatch_get_main_queue()) { () -> Void in
// Code runs on main queue!
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments