我想知道下面的代码是否可以。我想从“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