Diğer ViewController'daki bazı işlemleri tamamladıktan sonra yeni bir ViewController (özel bir AlertController) oluşturuyorum ve bundan sonra "İsteğe bağlı bir değer çıkarılırken beklenmedik bir şekilde sıfır bulundu" hatası var. İşte kod: Yeni ViewController örneğinin oluşturulmasında sıfır var
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")
}
}
Ve başka viewController içinde
Ben:CustomAlertController.showAlert(self, title: "Success!", message: "Operation done", okTitle: "OK")
sorun olduğunu titleLabel ve ayarlanması gereken diğer özellikler sıfır.
Herhangi bir yardım yararlı olabilir. Şimdiden teşekkürler!