Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何访问警报中Uitextfield的文本?_Swift_Uitextfield_Alert_Textfield_Pickerview - Fatal编程技术网

Swift 如何访问警报中Uitextfield的文本?

Swift 如何访问警报中Uitextfield的文本?,swift,uitextfield,alert,textfield,pickerview,Swift,Uitextfield,Alert,Textfield,Pickerview,我创建了一个带有两个文本字段的警报,第二个文本字段的inputView是一个pickerview。我可以通过alert.textfields?.first?.text访问第一个文本字段的文本。我想在第二个文本字段中显示选择器视图项,但我不知道如何访问选择器视图函数didSelectRow中的secondTextfield.text。 我怎样才能修好它 buttonAnimation(按钮:addButton) passwordStringArray.insert(“\(passwordLabel

我创建了一个带有两个文本字段的警报,第二个文本字段的inputView是一个pickerview。我可以通过alert.textfields?.first?.text访问第一个文本字段的文本。我想在第二个文本字段中显示选择器视图项,但我不知道如何访问选择器视图函数didSelectRow中的secondTextfield.text。 我怎样才能修好它

buttonAnimation(按钮:addButton)
passwordStringArray.insert(“\(passwordLabel.text??)”,位于:0)
让alert=UIAlertController(标题:\(passwordLabel.text??)”,消息:“自定义密码”,首选样式:。alert)
alert.addTextField{(notesTextfield)位于
notesTextfield.placeholder=“键入一些注释”
notesTextfield.textAlignment=.center
}
alert.addTextField{(categoryTextfield)位于
categoryTextfield.placeholder=“选择密码类别”
categoryTextfield.textAlignment=.center
categoryTextfield.inputView=self.picker
}
让actionSave=UIAlertAction(标题:“保存”,样式:。默认值){(取消按钮)在
self.disclose(动画:true,完成:nil)
self.passwordNotesArray.insert(“\(alert.textFields?.first?.text???)”,位于:0)
//self.passwordCategory.insert(categorytextfield.text)
self.performsgue(标识符为“segue”,发送方为self)
}
让actionCancel=UIAlertAction(标题:“取消”,样式:。默认值){(保存按钮)在
self.disclose(动画:true,完成:nil)
}
alert.addAction(actionCancel)
alert.addAction(actionSave)
self.present(警报、动画:true)
}
func pickerView(pickerView:UIPickerView,didSelectRow行:Int,不完整组件:Int){
//如何在此处访问alert.textfield.categorytectfield.text?
}

如果需要,您只能作为占位符进行操作。如果您想这样做,您必须创建一个警报函数,它可以从picker函数中获得一个参数。您是否希望它作为占位符?使用占位符非常简单。如果你想把数据放在那里,我认为这是不可能的,因为警报应该得到数据,而不是放在里面


要将数据放入警报,警报函数需要从pickerView中获取一个字符串参数。必须在pickerview didselect函数内部调用Alert。

查看这里的操作,您必须创建闭包:)我希望这有助于您理解闭包的含义是什么?它仍然不起作用:/