Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        6年前关闭。
                                                                                            
                
        
该程序有一部分:

dispatch_sync (dispatch_get_main_queue (), ^ {
    [startBtn setTitle: @ "Loading ..." forState: UIControlStateNormal];
    [self loadImages]; / / loading images - AssesLibrary
});

[self makeCollage];
NSLog (@ "Albums found:% lu", (unsigned long) [assetGroups count]);


从块dispatch_sync程序中出来,我需要首先执行[self loadImages](数据填充数组)的功能,然后再执行[self makeCollage]
如果没有dispatch_sync-则仅[self makeCollage]开始填充而不进行进一步处理,并给出错误。

建议如何做

最佳答案

添加 :

dispatch_queue_t currentQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(currentQueue, ^{

    __block UIImage *image=nil;
    dispatch_sync(currentQueue, ^{

        //download the image here
        image = [self loadImages];

    });

dispatch_sync(dispatch_get_main_queue(), ^{

        //handle the image to the user here on the main queue
        if (image != nil){
            [self makeCollage];
        } else
        {
            NSLog(@"Image isn't downloaded. Nothing to do.");
        }

    });
});

关于ios - 不要像在iOS 6中那样在iOS 7中工作dispatch_async ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19674874/

10-13 03:51