【发布时间】:2015-09-21 06:28:20
【问题描述】:
我有一个 iOS 应用程序,可在 Appstore 中找到。今天我测试了这个应用程序,当应用程序试图打开一个错误对话框时,它在我的 iPhone4 (iOS7) 上崩溃了。在 iPhone5s 上没有问题。
当我从 XCode 安装应用程序时,它可以工作...... XCode/Appstore 是相同的版本。 我在 XCode 中阅读了控制台以找出应用程序崩溃的原因。我收到了这个错误:
以下错误::*** 由于未捕获而终止应用程序 异常'NSInvalidArgumentException',原因:'应用程序试图 在目标上显示一个 nil 模态视图控制器
我做错了什么? 当我调用我的错误对话框时,我会这样做:
self.showAlert("Error.", message: "Wrong credentials.", owner: self);
报错方法:
func showAlert(title:NSString, message:NSString,owner:UIViewController) {
if let gotModernAlert: AnyClass = NSClassFromString("UIAlertController") {
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert);
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil));
owner.presentViewController(alert, animated: true, completion: nil);
}
else {
let alertView = UIAlertView(title: title, message: message, delegate: self, cancelButtonTitle: nil, otherButtonTitles: "OK");
alertView.alertViewStyle = .Default;
alertView.show();
}
}
最好的问候
【问题讨论】: