Some things need to be run on the mainThread as per the guidelines. One example is reloadData for a table. If I don't run this on mainThread I will get problems or even crashes. Other things like updating frames have to be done like this too.
I was wondering if this is a safe way to make sure something is run on the mainThread. I've tested it out some and it always seems to work, but it could be a bad practice.
The only problem I see is if somehow the performSelectorOnMainThread somehow didn't get called on the mainThread and it got stuck in an infinite loop
I was wondering if this is a safe way to make sure something is run on the mainThread. I've tested it out some and it always seems to work, but it could be a bad practice.
Code:
- (void) reloadTable
{
if ([NSThread isMainThread]) {
@synchronized (self.tableView) {
[self.tableView reloadData];
}
} else {
[self performSelectorOnMainThread:@selector(reloadTable) withObject:nil waitUntilDone:YES];
}
}
The only problem I see is if somehow the performSelectorOnMainThread somehow didn't get called on the mainThread and it got stuck in an infinite loop