Asynchronus way of image in for loop [closed]

余生颓废 提交于 2019-12-13 04:59:51

问题


I have an for loop , which consists of uiimageview inside it, everytime i add the image from the array which consits of url , i convert it to data and imagewithdata method am using it, it works for me perfectly but it takes long time , can we acheive it in lazy loading which is used in uitableview?

Pls help

Thanks in advance


回答1:


Instead of Lazzy Loading I used following way in UItableView and its working for me without scrolling issue .

 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {

            NSData *imageData ;

            imageData = [UICommonUtils imageDataFromString:profile.Photo];

            dispatch_sync(dispatch_get_main_queue(), ^(void) {


                    if([imageData length] > 1)
                    {
                        //UIImageView* imageView = (UIImageView*)[cell viewWithTag:100];
                        cell.ProfileImage.image = [UIImage imageWithData:imageData];
                    }
                    else
                    {
                        cell.ProfileImage.image = [UIImage imageNamed:kDefaultProfileImage];
                    }

                });

            imageData = nil;
        });


来源:https://stackoverflow.com/questions/18510909/asynchronus-way-of-image-in-for-loop

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