Before manipulating anything that can cause some drawing, you should make sure you're on the main thread.
For instance if you want to reload a UITableView from a detached thread, you should call:
[myTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
And if you have several statements that can cause drawing, you can have a separate method that do the drawing and make sure it's performed on the main thread:
- (void) asyncDoSomeStuff {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Do your stuff
...
// Update UI
[self performSelectorOnMainThread:@selector(refreshGUI) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void) refreshGUI {
[myTableView reloadData];
[myImageView setImage:[UIImage imageNamed:@"blabla.png"]];
...
}
And lastly if you're unsure about which thread is going to call a particular method that perform some drawing, then at the beginning of the method you can add the following statement, which will ensure that the whole method is going to execute on the main thread:
- (void) myMethod {
if(![NSThread isMainThread]) {
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:NO];
return;
}
// Do your stuff
}
Otherwise I don't think there is a solution to detect that some drawing is going to be performed outside of the main thread. For instance, anything related to UIKit should occur in the main thread.