Where is NSAlert.h in the iOS SDK? 的后续

有什么办法可以从 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 是一个同步函数,它显示警报并等待用户响应。在内部,它正在运行一个有限版本的消息循环,但就我的应用程序的其余部分而言,世界已经停止了;没有消息,没有事件,什么都没有。

最佳答案



只需完全按照您的描述进行操作:抛出警报,然后运行事件循环,直到警报 View 被关闭。此代码有效:

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];

关于ios - UIAlertView runModal,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6625872/

10-12 04:47