【发布时间】:2011-09-20 14:04:18
【问题描述】:
我想知道下面的代码是否可以。我试图通过“timedAlert”方法在 2 秒后自动关闭 alertView(并且在 alertView 中没有任何按钮)。
//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设置为“nil”,“[alertViewdismissWithClickedButtonIndex:0 animated:YES];”怎么办?东西工作???我尝试将cancelButton设置为“nil”并且它有效,但无法弄清楚如何......
P.S:我从另一个调用 timedAlert 方法
感谢任何帮助!谢谢!
【问题讨论】:
-
是的,你的代码没问题。你可以在这里阅读更详细的解释:iphonedevelopertips.com/user-interface/…
-
谢谢!但是当alertView中没有按钮时,我仍然知道dismissWithClickedBittonIndex如何正常工作。尤其是为什么接受按钮索引...请帮助!
-
我不太明白你的问题是什么。在dismissWithClickedBittonIndex 方法中,按钮索引是可选的。如果您传递 nil(或 0),则警报会简单地关闭。
-
好的。谢谢你的帮助!这就是我想知道的...... :)
标签: objective-c iphone uialertview