2011-12-29 67 views
0

我想要發生的情況,按順序:警報框彈出時顯示處理(無按鈕),主要處理功能被調用,當警報框完成時消失,然後我的導航控制器移動到系列中的下一個視圖。當其他視圖正在更改時,UIAlertView不顯示

實際發生的事情:窗口在應用程序處理時凍結,然後警報框在導航控制器切換到下一個視圖時立即顯示並消失。

如何解決這個問題的最佳建議?代碼: [_navigationController dismissModalViewControllerAnimated:NO]; //相機解散 UIAlertView *警報;

alert = [[[UIAlertView alloc] initWithTitle:@"Analyzing\nPlease Wait..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease]; 
[alert show]; 

[self processImage]; 

[alert dismissWithClickedButtonIndex:0 animated:YES]; 
[self gotoResults]; 
+0

使用這一個[self performSelector:@(processImage)] – userar 2011-12-29 06:36:41

回答

2
alert = [[[UIAlertView alloc] initWithTitle:@"Analyzing\nPlease Wait..." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil] autorelease]; 
[alert show]; 

當調用[alert show] ,UI事件被推入主運行循環。您可以在其他功能中處理其他任務。例如,名爲foo的函數處理其他任務。在致電[alert show]後,我們致電[self performSelector:@selector(foo) withObject:nil afterDelay:0.1]調用foo。這將給運行循環一些時間來處理警報視圖的顯示事件。

- (void)foo { 
    UIAlert *alert = ... ///< come from above 
    [self processImage]; 

    [alert dismissWithClickedButtonIndex:0 animated:YES]; 
    [self gotoResults]; 
} 

編輯: 你可以閱讀有關-performSelector:withObject:afterDelay:在this apple official document。可以分配0.0作爲參數afterDelay,並且文檔說:

delay


被髮送的消息,該消息之前的最小時間。指定 延遲爲0並不一定會使選擇器立即執行 。選擇器仍然在線程的運行循環中排隊,並且儘快執行 。

+0

這似乎是一個好主意,但它有可能沒有在0.1秒內顯示窗口?就像在某些情況下,UI可能需要更長時間才能趕上?或者情況並非如此? – Jason 2011-12-29 14:53:10

+0

我編輯了我的問題。 – AechoLiu 2011-12-30 00:46:35

1

[自processImage來]在主線程中運行導致窗口凍結問題...... 所以你可以使用

[NSThread detachNewThread: .....] 

調用AlertView方法

相關問題