ios - "[UIAlertView show]"不显示消息弹窗立即返回

标签 ios objective-c cocoa-touch cocos2d-iphone uialertview

我正在尝试为 iOS 实现错误弹出功能。我当前的实现:

void SysErrorAlert(NSString * title, NSString * message, ...)
{
    NSString * contents = nil;

    va_list args;
    va_start(args, message);
    contents = [[NSString alloc] initWithFormat:message arguments:args];
    va_end(args);

    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:title
                                                     message:contents
                                                    delegate:nil
                                           cancelButtonTitle:@"Cancel"
                                           otherButtonTitles:@"OK", nil];
    [alert show];

    // tried this but popup still never shows...
    //for (;;) { }
}

但是,“[alert show]”会立即返回,而不会显示弹出对话框。 我需要将对话框显示在当前应用程序屏幕的顶部并阻止调用线程,直到用户单击其中一个按钮。应用程序将在函数返回后终止。

该应用程序正在运行 Cocos2d,所以 Cocos 绘图可能会干扰 UIAlertView...但我对 iOS 编程还很陌生,可能在这里遗漏了一些明显的东西。

注意:我没有在实际设备上测试过这个,只在模拟器上测试过。这可能是模拟器的限制/错误吗?

最佳答案

看起来你必须向 cocos2d 寻求帮助才能为警报 View 找到正确的父级 这篇较旧的文章提出了一个大纲: http://www.cocos2d-iphone.org/forums/topic/how-to-popup-a-uialertview-with-cocos2d/

关于ios - "[UIAlertView show]"不显示消息弹窗立即返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22725232/

相关文章:

ios - 如何使用 'SWRevealViewController' 在 UITabBarItem 而不是 UIButton 中设置 RevealToggle 方法?

ios - 无法从 NSDictionary 获取 int

objective-c - 如何将 NSTextView 添加到 NSScrollView 中?

ios - 如何在 iOS 中制作流畅的布局?

iOS 9 扩展状态栏错误?

cocoa-touch - iOS 在 IB 中或以编程方式设置 Root View Controller

ios - XCode5 assets目录的切片工具如何使用切片的图片

ios - Objective-C - 设备无法识别的日期格式

iphone - 如何在更多部分获取 UITabBarItem 的标题?

ios - 在 UITableView 之上为 UIView 添加阴影