问题
I have a UIView
which creates and inserts views using GCD
. It's working on iOS7
but the UIImageView
s takes forever to show.
Here's the sample code that I am using.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
for (int i = 0; i < 200; i++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(77 * i, 0, 77, 88)];
[scrollView addSubview:view];
dispatch_queue_t queue = dispatch_queue_create("image", NULL);
dispatch_async(queue, ^{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo@hd.png"]];
imageView.frame = CGRectMake(0, 0, 77, 88);
[view addSubview:imageView];
dispatch_async(dispatch_get_main_queue(), ^{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
label.text = [NSString stringWithFormat:@"Name %d", i];
[label sizeToFit];
label.center = CGPointMake(38.5, 20);
[imageView addSubview:label];
});
});
[scrollView setContentSize:CGSizeMake(view.frame.size.width * (i+1), view.frame.size.height)];
}
[self.view addSubview:scrollView];
By the way, I am creating many UIView
s that's why it is threaded. Around 200 views at max.
How should I make it work? The methods inside the dispatch blocks are being called, it is just the UIView
s are not being displayed.
Thanks!
来源:https://stackoverflow.com/questions/19132883/ios7-uiimageview-takes-forever-to-appear