UIAlertView runModal

Iro*_*san 3 uialertview uiactionsheet ios

跟帖到哪里NSAlert.h在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;
}
Run Code Online (Sandbox Code Playgroud)

runModal是一个同步函数,它显示警报并等待用户响应.在内部,它正在运行一个有限版本的消息循环,但就我的应用程序的其余部分而言,世界已经停止; 没有消息,没有事件,没有.

Jer*_*man 9

在内部,它正在运行一个有限版本的消息循环,但就我的应用程序的其余部分而言,世界已经停止

只需按照您的描述执行:抛出警报,然后运行事件循环,直到警报视图被解除.此代码有效:

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];
Run Code Online (Sandbox Code Playgroud)