As pointed out by bbum here, the doc says: "For the most part, UIKit classes should only be used from the main thread of an application This is especially true for derived classes UIResponder or involve the manipulation of user interface of your application in any way. ".
I thought I understood that the methods of drawings could not be called in a background thread, so that the creation could be done in the background, as the drawRect method is only called when the view is added. But maybe i am wrong.
In summary, does that this kind of code is risky?
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSString *fileName = [pathToModel stringByAppendingPathComponent:[[compDico valueForKey:@"fileName"] lastPathComponent]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:
fileName]];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 62, 190, 20)];
[label setText:[[someArray objectAtIndex:i-1] someText]];
[label setNumberOfLines:0];
label.font=[UIFont fontWithName:@"arial" size:10.0f];
[label setBackgroundColor:[UIColor clearColor]];
// Create some other view here
// ...
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:imageView];
[self.view addSubview:label];
//Add other view here
// ...
});
});
Thanks for in advance your responses!