Reputation: 580
I get the following error, and i have no clue how to avoid it, can someone please help me
bool _WebTryThreadLock(bool), 0x1ea990: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
- (void)loadImg {
NSData* image = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://images.sugarscape.com/userfiles/image/DECEMBER2010/Lozza/HarryStyles2.jpg"]];
UIImage* img = [[UIImage alloc] initWithData:image] ;
[self performSelectorInBackground:@selector(showImg:) withObject:img];
}
Upvotes: 0
Views: 138
Reputation: 753
According to Threading Programmin Guide: Thread Safety Summary, you should invoke UIView's operations on main thread. Try [self performSelectorOnMainThread:@selector(showImg:) withObject:img waitUntilDone:YES].
Upvotes: 0
Reputation: 38728
It is not safe to update UI from a background thread, which I am assuming you are doing here
[self performSelectorInBackground:@selector(showImg:) withObject:img];
I think you may have got it the wrong way round you want to:
Upvotes: 0
Reputation: 23722
Don't call any UIKit methods from threads other than the main thread. performSelectorInBackground:withObject:
executes showImg:
on a secondary thread, and if you call any UIKit methods there, that might be the problem.
It is actually explained in plain English:
This may be a result of calling to UIKit from a secondary thread
Upvotes: 3