iOS - another thread needs to send reloadData to the mainthread
[self.tableView performSelectorOnMainThread:@selector(reloadData)
withObject:nil
waitUntilDone:NO];
Do I need to use @synchronized when calling UITableView reloadData method?
You shouldn't call reloadData from threads other than the main thread.
See this similar question:
iOS - another thread needs to send reloadData to the mainthread
Reloading UITableView on Main Thread does not always work
So, the problem was that I added a prototype UITableViewCell to my UITableView in the Interface Builder (IB) of Xcode 7 Beta 4. I don't know why, but adding a prototype UITableViewCell to a UITableView in the IB caused problems in all the UITableViews. After deleting the prototype UITableViewCells again from the UITableViews in my project in IB everything works just fine. This way my code creates a couple of UITableViewCells upon launch and reuses them if I change their data and call reloadData() on the UITableView.
For an IM app, if I reloadData frequently, Is it possible the main thread be blocked? If yes, any good way to solve it?
You don't have to reload the whole table view every time, but you should only reload the section (or row) with the new message using - (void)reloadSections:(NSIndexSet *)sections
or - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
.
To answer your question, if the main thread is blocked by a long operation it won't send you a memory warning but your UI will be blocked making your app unresponsive therefore impacting the user experience.
Swift UITableView reloadData in a closure
UIKit isn't thread safe. The UI should only be updated from main thread:
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
Update. In Swift 3 and later use:
DispatchQueue.main.async {
self.tableView.reloadData()
}
Related Topics
Iphone:Get the File Path Which Is Within Subfolder of Resource Folder
Setting a Rotation Point for Cgaffinetransformmakerotation Swift
How to Make a Grouped Barchart with iOS-Charts
Ios- Check Whether Current Time Is Between Two Times or Not
How to Properly Add Child View Controller in iOS 8 with Swift
Secure Contents in Documents Directory
Youtube Video Autoplay Inside Uiwebview
Geofire Query on User Location
Measuring Time Accurately in Swift for Comparison Across Devices
Ios-8 and Later - Uitableview Inside an Uialertcontroller
Making Phone Calls on the Iphone
How Can One Enable Keyboard Like in Imessages/Fb Messenger in Landscape Mode at iOS8
Module 'Googlemobileads' Not Found in iOS
Detox: iOS Simulator How to Confirm Alert Message
Nspredicate Filtered by Year Moth Day
Detecting iOS Version Number from User Agent Using Regular Expressions
Memory Leak with "Libbacktracerecording.Dylib" in React Native iOS Application