Xcode7 UIAlertController 获取用户数据

Xcode7 UIAlertController to get user data

我需要一些帮助来从栏按钮中拉出自定义警报。 objective 是弹出警报,要求用户输入标题和描述。警报将有两个文本字段,一个用于标题,一个用于详细信息,带有创建和取消按钮。

代码如下,但我在 Xcode 7.0.1:

中遇到两个相同的错误

无法调用 non-function 类型“[UITextField]”的值

此错误发生在这些行上:

     let itemTitle = alert.textFields!(0) as UITextField!
     let itemDetail = alert.textFields!(1) as UITextField!

完整代码:

@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)

尝试在此处使用方括号而不是圆括号:

    alert.textFields![0]