I started a thread in a UIview as a background thread which transfer data for the view. However, crash happens in such situation: When I left the view at the very time that the thread is trying to transfer data.
I didn't get quite clear with the relationship between the UIview object and thread. I guess it crashes because the thread was trying to visit UIview members or methods, which were not existed any more. So, I wonder what happened to the thread if the UIView which detach it has been left.
This is my detaching code:
- (void)reloadData {
isLoaded = NO; //UIView member.
[NSThread detachNewThreadSelector:@selector(getThreadInAnotherThread) toTarget:self withObject:nil];
}
- (void)getThreadInAnotherThread {
//Loading code
isLoaded = YES;
[self performSelectorOnMainThread:@selector(reloadTable) withObject:nil waitUntilDone:YES];
}
And I didn't do anything in viewDidDisappear.