Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未异步加载UIImage_Ios_Objective C_Image_Url_Asynchronous - Fatal编程技术网

Ios 未异步加载UIImage

Ios 未异步加载UIImage,ios,objective-c,image,url,asynchronous,Ios,Objective C,Image,Url,Asynchronous,我想从url获取图像,我正在这样做: for(int i = 0; i < 50; i++) {NSString *MyURL=[NSString stringWithFormat:@"http://*********/tatoo/%@/%@%d.png" ,@"b",@"b",i+1]; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); disp

我想从url获取图像,我正在这样做:

for(int i = 0; i < 50; i++)
{NSString *MyURL=[NSString stringWithFormat:@"http://*********/tatoo/%@/%@%d.png" ,@"b",@"b",i+1];


    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
    dispatch_async(queue, ^(void) {
        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]];

                             UIImage* image = [[UIImage alloc] initWithData:imageData];
                             if (image) {
                                 dispatch_async(dispatch_get_main_queue(), ^{
                                     [tmp addObject:image];
                                 });
                             }
                             });

}

images = [[NSArray alloc]initWithArray:tmp];
for(int i=0;i<50;i++)
{NSString*MyURL=[NSString stringWithFormat:@“http://************/tatoo/%@/%@%d.png”,“b”,“b”,i+1];
调度队列=调度获取全局队列(调度队列优先级高,0ul);
调度异步(队列,^(无效){
NSData*imageData=[NSData DATA WITHCONTENTSOFURL:[NSURL URLWithString:MyURL]];
UIImage*image=[[UIImage alloc]initWithData:imageData];
如果(图像){
dispatch\u async(dispatch\u get\u main\u queue()^{
[tmp addObject:image];
});
}
});
}
images=[[NSArray alloc]initWithArray:tmp];

Url有效,但tmp为空。你知道这里怎么了吗?任何帮助都将不胜感激

异步下载尚未完成,您需要等待

使用操作队列或调度组等待它们全部完成,然后可以使用阵列


还请注意,您不能保证阵列中图像的任何顺序,因为您不知道每次下载需要多长时间。另外,最好不要同时开始60次下载…

您可以使用AsyncImageView加载图像,而不会影响您的UI

从下载第三方类


这将在后台加载图像。

在添加图像数据之前,您是否初始化了tmp

tmp =[NSArray alloc]init];

循环之前初始化

何时为空?展示code@Wain空时,我想添加到图像arrayi做了你说的,但从url的图像没有加载。我使用它在数组中添加图像。[tmp addObject:storeImage.image];可以吗?不,上面的代码将直接将图像添加到ImageView中,将图像添加到数组中有什么特殊之处?无论如何,你会在一些imageview中显示它,对吗?你有想法吗?如果我不向下滚动,为什么图像不会显示?你在第一个逻辑中初始化了tmp数组吗?
tmp =[NSArray alloc]init];