gpt4 book ai didi

Xcode7 UIAlertController 获取用户数据

转载 作者:行者123 更新时间:2023-11-30 13:59:24 25 4
gpt4 key购买 nike

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

代码如下,但我在 Xcode 7.0.1 中遇到两个相同的错误:

无法调用非函数类型“[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]

关于Xcode7 UIAlertController 获取用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33177790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com