iOS7 : UIImageView Takes Forever to Appear

喜夏-厌秋 提交于 2019-12-24 10:54:08

问题


I have a UIView which creates and inserts views using GCD. It's working on iOS7 but the UIImageViews 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 UIViews 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 UIViews are not being displayed.

Thanks!

来源:https://stackoverflow.com/questions/19132883/ios7-uiimageview-takes-forever-to-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!