ios - 在自己的窗口中显示 UIAlertController 时出现 NSException

标签 ios swift uisplitviewcontroller uiwindow nsexception

我试图在 UISplitViewController 上显示 UIAlertController。我已经尝试了在此网站上找到的所有内容,并且坚持使用此处找到的扩展。

扩展 UIAlertController {

func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
        let alertWindow = UIWindow(frame: UIScreen.main.bounds)
        alertWindow.rootViewController = UIViewController()
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        alertWindow.makeKeyAndVisible()
        alertWindow.rootViewController?.present(self, animated: animated, completion: completion)
}

我在执行 Present 后立即收到异常,并且看不到堆栈跟踪,并且未触发异常断点。

libc++abi.dylib:以 NSException 类型的未捕获异常终止

它在 UISplitViewController 折叠的手机上呈现良好。我错过了什么?

最佳答案

潜在问题是UIWindowLevelAlert + 1;。尝试使用 UIWindowLevelNormal 代替。新窗口将放置在默认窗口上方。以及上面的 UISplitViewController

func presentInOwnWindow(animated: Bool, completion: (() -> Void)?) {
    let alertWindow = UIWindow(frame: UIScreen.main.bounds)
    alertWindow.rootViewController = UIViewController()
    alertWindow.windowLevel = UIWindowLevelNormal;
    alertWindow.makeKeyAndVisible()
    alertWindow.rootViewController?.present(self, animated: animated, completion: completion)
}

关于ios - 在自己的窗口中显示 UIAlertController 时出现 NSException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47228651/

相关文章:

ios - 无法反转表格 View

swift - 使用 DispatchQueue 管理 pdflatex 生成的同一文件更改的多个事件

facebook - 试图从 Facebook 获取用户生日,但我没有得到。我究竟做错了什么?

swift - 终端命令 : handle special characters in filename

ipad - 如何使用 UISplitViewController 从 viewDidUnload 中恢复(出现内存警告后)

iOS faSTLane 传递元数据

ios - 如何在 AVCaptureSession 上设置音频采样率?

ios - 将值从自定义 View 传递到主视图 Controller - Swift

ios - Split View中的 Collection View Controller 不更新

ios - UISplitViewController - 隐藏主滑入 View