Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Objective c 使用调度异步、can';是否在同一控制器上触发两个函数调用?_Objective C_Cocoa_Grand Central Dispatch - Fatal编程技术网

Objective c 使用调度异步、can';是否在同一控制器上触发两个函数调用?

Objective c 使用调度异步、can';是否在同一控制器上触发两个函数调用?,objective-c,cocoa,grand-central-dispatch,Objective C,Cocoa,Grand Central Dispatch,我的AppDelegate中有以下方法。我找不到一种方法来更新updateView上的标签并通过ASIHTTPRequest执行上载。在下面的代码中,它将执行上载(startUpload),但不更新标签(updateLabel)。如果我注释掉对startUpload的调用,它将更新标签。我还尝试在uploadViewController中创建一个调度队列,结果类似,我只能使用这两种方法中的一种 - (void) showProgressView:(NSString *)filePath {

我的AppDelegate中有以下方法。我找不到一种方法来更新updateView上的标签并通过ASIHTTPRequest执行上载。在下面的代码中,它将执行上载(startUpload),但不更新标签(updateLabel)。如果我注释掉对startUpload的调用,它将更新标签。我还尝试在uploadViewController中创建一个调度队列,结果类似,我只能使用这两种方法中的一种

- (void) showProgressView:(NSString *)filePath {
    NSView *view = [uploadViewController view];
    dispatch_queue_t queue = dispatch_get_global_queue(0,0);
    dispatch_async(queue, ^{
        // assigns the upload view to the root NSPanel
        [box setContentView:view];
    });
    dispatch_async(queue, ^{
        // starts the upload using ASIHTTPRequest
        [uploadViewController startUpload:filePath];
    });
    dispatch_async(queue, ^{
        // updates a label in the upload view
        [uploadViewController updateLabel];
    });
}
在UploadViewController中:

-(void)startUpload:(NSString *)filePath {
    HandZipper *handZipper = [HandZipper alloc];
    zipPath = [handZipper compressHands:(filePath):(processStatus)];   

    ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ignore"]] autorelease];

    [request setRequestMethod:@"PUT"];
    [request setPostBodyFilePath:zipPath];
    [request setShouldStreamPostDataFromDisk:YES];
    [request setDelegate:self];
    [request setUploadProgressDelegate:progressIndicator];
    [request setDidFinishSelector:@selector(postFinished:)];
    [request setDidFailSelector:@selector(postFailed:)];
    [request startSynchronous]; 

}

您应该始终更新主线程上的UI元素。如果您知道将从主线程调用
showProgressView:
,则从
[box setContentView:view]周围删除dispatch\u async
[uploadViewController updateLabel]showProgressView:
,则只需使用
dispatch\u get\u main\u queue(void)
而不是
queue