我试图在 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/