UIAlertView runModal
有没有办法从 UIAlertView 获得类似 NSAlert runModal 的行为?或者来自 UIActionSheet?
我计划仅在调试版本中使用,因此我不关心它的外观或是否使用未记录的功能。
编辑:
NSAlert 是 OS X SDK 的一部分,类似于 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 是一个同步函数,它显示警报并等待用户响应。它在内部运行消息循环的有限版本,但就我的应用程序的其余部分而言,世界已经停止了;没有消息,没有事件,什么都没有。
Followup to Where is NSAlert.h in the iOS SDK?
Is there any way to get NSAlert runModal like behavior from a UIAlertView? Or from a UIActionSheet?
I'm planning on using only in debug builds so I'm not concerned with how it looks or if it uses undocumented functionality.
Edit:
NSAlert is part of the OS X SDK and is similar to MessageBox in Win32. It allows you to synchronously prompt the user for something. Here's an example:
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 is a synchronous function, it shows the alert and waits for user response. Internally it is running a limited version of the message loop, but as far as the rest of my application is concerned, the world has stopped; no messages, no events, nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要这种行为,您必须自己编写。小心,如果您阻塞主队列太长时间,您的应用程序将受到监视。
UIAlertView 为您提供模态行为,并且最终将以与您的自定义类相同的方式工作。您可能会考虑使用基于块的包装器来包装 UIAlertView 并允许您为按钮操作回调设置块。
You'll have to write your own if you want this behavior. Careful, if you block the main queue for too long, your app will be watchdog'd.
UIAlertView gives you modal behavior, and will end up working the same way your custom class will. You might consider using a block-based wrapper that wraps up UIAlertView and allows you to setup blocks for the button action callbacks.
只需按照您所描述的操作即可:抛出警报,然后运行事件循环直到警报视图出现被解雇了。这段代码的工作原理:
Just do exactly what you described: throw up the alert, then run the event loop till the alert view gets dismissed. This code works: