2011-07-11 56 views
0

我有以下的委託方法的UIAlertView中:解聘UIAlertView中編程

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex { 

但是我有一個問題。在這種方法中,我會執行一些邏輯並執行一些需要少量時間的代碼。我想在完成所有這些操作之前關閉alertView。我想在該方法的最上方關閉警報視圖。這樣,當用戶點擊alertView上的一個按鈕時,應用程序似乎不會在執行下一行代碼時凍結一秒。

回答

4

請使用委託方法-alertView:didDismissWithButtonIndex:來代替它 - 一旦警報視圖已從屏幕上移除,它就會被調用,這至少會掩蓋您的應用程序擁有或更好使用後臺線程的滯後時間。與-performSelectorInBackground:withObject:,來處理你需要做的任何處理。

2

使用其他委託方法,而不是

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; 

你應該也可能執行的代碼的其他行你異步提,以免在所有凍結UI 。

12

要關閉警報programaticly做:
/* Your Processing Code Here */ [theAlertView dismissWithClickedButtonIndex:0 animated:YES];
的[theAlertView dismissWithClickedButtonIndex:0動畫:YES];會使警報消失

+2

不起作用。你的意思是:'[theAlertView dismissWithClickedButtonIndex:0 animated:YES];' – bearMountain

+0

雅,非常感謝 –