Я создал новый ViewController (который является настраиваемым AlertController) после завершения некоторых операций в другом ViewController, и после этого имеет ошибку «неожиданно нашел нуль при развертывании необязательного значения». Вот код:Не удалось создать новый экземпляр ViewController
class CustomAlertController: UIViewController {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var okButton: UIButton!
internal func loadFromStoryboard() -> CustomAlertController! {
let alertsStoryboard = UIStoryboard(name: "Alerts", bundle: NSBundle.mainBundle())
let alertControllerStoryboardVC = alertsStoryboard.instantiateViewControllerWithIdentifier("CustomAlertController") as! CustomAlertController
return alertControllerStoryboardVC
}
class func showAlert(controller: UIViewController? = nil, title: String, message: String, okTitle: String, completion:()->Void = {}) {
let customAlertVC = CustomAlertController().loadFromStoryboard()
customAlertVC.modalPresentationStyle = UIModalPresentationStyle.Custom
let localTransitioningDelegate = AlertTransitioningDelegate()
customAlertVC.transitioningDelegate = localTransitioningDelegate
customAlertVC.titleLabel.text = title
customAlertVC.messageLabel.text = message
customAlertVC.okButton.titleLabel?.text = okTitle
if controller != nil {
controller?.modalPresentationStyle = .OverCurrentContext
controller?.presentViewController(customAlertVC, animated: true, completion: nil)
}
else {
print("something went wrong, friend")
}
}
И в другом ViewController у меня есть:
CustomAlertController.showAlert(self, title: "Success!", message: "Operation done", okTitle: "OK")
Проблема заключается в том titleLabel и другие свойства, которые должны быть установлены в ноль.
Любая помощь была бы полезна. Спасибо заранее!