2012-07-18 33 views
0

當我從第二個視圖返回到我的mainView時,我正在處理我的第二個視圖的viewDidDisappear方法中的某些內容。問題是,我的mainView由於應用程序必須做的工作而卡住了。即使我使用GCD,用戶界面也會卡住

這裏是我做的:

-(void)viewDidDisappear:(BOOL)animated 
{ 
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); 

    dispatch_async(queue, ^{ 

    dbq = [[dbqueries alloc] init]; 

    [[NSNotificationCenter defaultCenter] postNotificationName:@"abc" object:nil]; 
    //the notification should start a progressView, but because the whole view gets stuck, I can't see it working, because it stops as soon as the work is done 

    dispatch_sync(dispatch_get_main_queue(), ^{ 

    //work  

    }); 
}); 

我在做什麼錯? 在此先感謝!

回答

3

您需要執行dispatch_asyncqueue的工作。您目前正在主線程中完成這項工作(假設// Work註釋是它發生的地方),另外還阻止了您的工作線程等待這項工作。

嘗試重新安排你的GCD調用位:

-(void)viewDidDisappear:(BOOL)animated 
{ 
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); 

    dbq = [[dbqueries alloc] init]; 

    [[NSNotificationCenter defaultCenter] postNotificationName:@"abc" object:nil]; 

    dispatch_async(queue, ^{ 

     // Perform work here 

     dispatch_async(dispatch_get_main_queue(), ^{ 

      // Update UI here 

     }); 
    }); 
} 
+1

沒有,問題是他做的主線程上的工作。 – 2012-07-18 12:44:42

+0

視圖仍然卡住,沒有加載指示器 – oybcs 2012-07-18 12:44:57

+0

所以我必須創建另一個線程?但是,我必須使用這個GCD thingy嗎?因爲,如果它在另一個線程上,爲什麼我需要這個? – oybcs 2012-07-18 12:46:50

相關問題