Я пытаюсь показать UIAlertController
с UITextView
. Когда я добавляю строку:
//Add text field
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
}
Я получаю ошибку во время Runtime
:
фатальная ошибка: неожиданно найден ноль при развертывании необязательного значения
let alertController: UIAlertController = UIAlertController(title: "Find image", message: "Search for image", preferredStyle: .Alert)
//cancel button
let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in
//cancel code
}
alertController.addAction(cancelAction)
//Create an optional action
let nextAction: UIAlertAction = UIAlertAction(title: "Search", style: .Default) { action -> Void in
let text = (alertController.textFields?.first as! UITextField).text
println("You entered \(text)")
}
alertController.addAction(nextAction)
//Add text field
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.textColor = UIColor.greenColor()
}
//Present the AlertController
presentViewController(alertController, animated: true, completion: nil)
Это представлено внутри моего ViewController
через IBAction
.
Я скачал код отсюда, и он отлично работает. Я скопировал и вставил этот метод в мой код, и он сломался. Присутствие себя в последней строке не оказывает влияния.