2011-03-10 90 views
1

我使用UIAlertView與「請稍候」和UIActivityIndi​​catorView。我使用問題解僱UIAlertView

{ 
    ... 
    [self performSelectorInBackground:@selector(sh) withObject:nil]; 
    //i've tried also 
    //[NSThread detachNewThreadSelector:@selector(showWaiting) toTarget:self withObject:nil]; 
    ... 
} 

- (void)showWaiting { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    [waitingAlert show]; 
    [pool drain]; 
} 

當出現警報時,屏幕變暗和無效。而當時間關閉提醒來了,我做

[waitingAlert dismissWithClickedButtonIndex:0 animated:NO]; 

後此警告消失,但有時(機率約爲5%)的屏幕仍然是黑暗和不活動之前。 有人遇到過這樣的問題嗎? 謝謝!

+0

是「@selector(sh)」的錯誤嗎?上面沒有定義「sh」的方法。 – occulus 2011-03-10 13:07:50

+0

我們需要查看更多代碼。你在哪裏叫dismissWithClickedButtonIndex:from? – occulus 2011-03-10 13:08:38

回答

3

這是不是你要找的答案...但它是「正確」的答案,將節省您在長期運行一段時間:

你濫用UIAlertView中。它不應該用於進度指示器和「請稍候」對話框。它的目的是被用戶擊中一個按鈕 - 一個UIAlertView永遠不會消失在它自己的 (更正:實際上,它可以;蘋果的API支持解僱它,但這樣的事情應該非常小心地使用)

如果繼續以這種方式濫用UIAlertView,當應用商店提交期間應用被拒絕時,請不要感到驚訝,然後您必須以其他方式重做。

也請看到我的回答這個問題:

Multiple AlertViews - Remove the alertview that is behind another alertview

1

由於occulus狀態避免使用UIAlertView中這樣,

我建議MBProgressHUD,這是非常容易使用,看起來不錯,設計以此目的。

0

您必須在NSAutoreleasePool之外創建,顯示併發布警報。例如,你打吧背景:

... 
[NSThread detachNewThreadSelector:@selector(showWaiting) toTarget:self withObject:nil]; 
... 

並且電話自動釋放池:

- (void)showWaiting { 
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    [self performSelectorInMainThread:@selector(showMyAlert) withObject:nil waitUntilDone:NO]; 
    //[waitingAlert show]; 
    [pool drain]; 
} 

然後,你必須顯示利用主線程警報。

- (void)showMyAlert { 
    UIAlertView * myAlert = [[UIAlertView alloc] initWith...]; 
    [myAlert show]; 
    [myAlert release]; 
} 

如果您嘗試顯示autorelease池內的警報,並且這是排空,然後警報消失。

我希望這有助於!