Where is NSAlert.h in the iOS SDK?的后续行动
有没有办法从NSAlert runModal获得类似于UIAlertView的行为?还是来自UIActionSheet?
我计划只在调试版本中使用,所以我不关心它的外观,也不关心它是否使用无文档的功能。
编辑:
NSAlert是OS的一部分,与Win32中的MessageBox类似。它允许您同步提示用户某些内容。下面是一个例子:
NSAlert * myAlert=[[NSAlert alloc] init];
[myAlert setMessgeText:@"This is my alert"];
[myAlert addButtonWithTitle:@"button 1"];
[myAlert addButtonWithTitle:@"button 2"];
switch ([myAlert runModal]) {
case NSAlertFirstButtonReturn:
//handle first button
break;
case NSAlertSecondButtonReturn:
//handle second button
break;
}runModal是一个同步函数,它显示警报并等待用户响应。在内部,它运行的是消息循环的有限版本,但就我的应用程序的其余部分而言,世界已经停止;没有消息,没有事件,什么也没有。
发布于 2011-07-08 17:33:37
在
内部,它正在运行消息循环的有限版本,但就我的应用程序的其余部分而言,世界已经停止了。
只需按照您所描述的那样做:抛出警报,然后运行事件循环,直到警报视图被排除。此代码适用于:
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"O rlly?" message:nil delegate:nil
cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
NSRunLoop *rl = [NSRunLoop currentRunLoop];
NSDate *d;
while ([alert isVisible]) {
d = [[NSDate alloc] init];
[rl runUntilDate:d];
[d release];
}
[alert release];发布于 2011-07-08 17:21:39
如果你想要这样的行为,你必须自己写。小心点,如果你把主队列阻塞太久,你的应用程序就会被监视。
UIAlertView给出了模式行为,并将以您的自定义类的方式结束工作。您可能会考虑使用一个基于块的包装器来封装UIAlertView,并允许您为按钮操作回调设置块。
https://stackoverflow.com/questions/6625872
复制相似问题