我想知道下面的代碼是否可以。我想從「timedAlert」方法中2秒後自動關閉alertView(並且沒有alertView中的任何按鈕)。UIAlertView沒有任何按鈕
//this is in another method
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
[alert release];
[self timedAlert];
}
-(void)timedAlert
{
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:2];
}
-(void)dismissAlert:(UIAlertView *) alertView
{
[alertView dismissWithClickedButtonIndex:nil animated:YES];
}
如果alertView的cancelButton被設置爲 「無」,將如何在 「[alertView dismissWithClickedButtonIndex:0動畫:是];」事情工作?我試圖使cancelButton「無」和它的工作,但不能弄清楚如何....
P.S:我叫timedAlert方法從另一個
任何幫助表示讚賞!謝謝!
是的,你的代碼是好的。你可以在這裏閱讀更詳細的解釋:http://iphonedevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html – adamsiton
謝謝!但我仍然得到disviewWithClickedBittonIndex如何在alertView中沒有按鈕時正常工作。特別是爲什麼按鈕索引被接受...請幫助! – Balaram
我不太明白你的問題。在dismissWithClickedBittonIndex方法中,按鈕索引是可選的。如果你通過零(或0),比警報簡單地解僱。 – adamsiton