I need some help with pulling up a custom alert from a bar button. The objective is to have the alert pop up asking the user to input the title and description. The alert is going to have two text fields, one for title and one for details, with a Create and Cancel button.
The code is below but I'm getting two of the same errors in Xcode 7.0.1:
Cannot call value of non-function type '[UITextField]'
This error is happening on these lines:
let itemTitle = alert.textFields!(0) as UITextField!
let itemDetail = alert.textFields!(1) as UITextField!
Full code:
@IBAction func addNewToDoListItem(sender: UIBarButtonItem) {
var alert = UIAlertController(title: "New ToDo Item", message: "Please enter a title and details for the new ToDo list item", preferredStyle: UIAlertControllerStyle.Alert)
var createItemAction = UIAlertAction(title: "Create", style: UIAlertActionStyle.Default) { (alertAction) -> Void in
let itemTitle = alert.textFields!(0) as UITextField!
let itemDetail = alert.textFields!(1) as UITextField!
}
var createCancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)
alert.addTextFieldWithConfigurationHandler { (textField) ->
Void in
textField.placeholder = "Title"
}
alert.addTextFieldWithConfigurationHandler { (textField) ->
Void in
textField.placeholder = "Details"
}
alert.addAction(createItemAction)
alert.addAction(createCancelAction)
self.presentViewController(alert, animated: true, completion: nil)