0
我在我的AppDelegate中有以下方法。我無法找到更新updateView上的標籤並通過ASIHTTPRequest執行上傳的方法。在下面的代碼中,它將執行上載(startUpload),但不更新標籤(updateLabel)。如果我註釋掉對startUpload的調用,它將更新標籤。我也嘗試在uploadViewController中創建一個調度隊列,並且有類似的結果,我只能使用這兩種方法中的一種。使用dispatch_async時出現問題,無法在同一個控制器上觸發兩個函數調用?
- (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];
}
ty,ty。很好解釋和它的工作。 –