如何在单击按钮时获取文本字段的选定文本? pickerview 被设置为文本字段的输入视图。 Swift
how to get selected text of textfield on button click? pickerview is set as an inputview to the textfield. Swift
目前我的输出显示的是来自文本字段内 pickerview 的选定值。
现在我的问题是我想在提交按钮上访问所有这些值并想在另一个视图控制器中显示如何做到这一点?。让我解释一下我的场景,我的第一个 vc 被设置为来自重定向到此页面的 collectionviewcell m 之一的 collectionview。
注意:我已经知道如何在两个视图控制器之间传递数据。但它在我的 case.Please 帮助中不起作用。
代码
@IBAction func StaffAtten_Action(_ sender: Any) {
// let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "StaffAttendence_SecondPage") as! StaffAttendence_SecondPage
//
// secondVC.a = active_text.text!
// secondVC.b = active_text.text!
// secondVC.c = active_text.text!
// secondVC.savedata.append(year.text!)
// secondVC.savedata.append(month.text!)
// secondVC.savedata.append(institute.text!)
}
}
您遇到的问题是您正在实例化一个全新的 VC 并将数据传递给它。实际呈现的VC不是您创建的
因为你有一个 segue 连接两个 VCs,覆盖 prepare(for:sender:)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? StaffAttendence_SecondPage {
vc.a = ...
vc.b = ...
// pass the rest of the data here...
}
}
目前我的输出显示的是来自文本字段内 pickerview 的选定值。
现在我的问题是我想在提交按钮上访问所有这些值并想在另一个视图控制器中显示如何做到这一点?。让我解释一下我的场景,我的第一个 vc 被设置为来自重定向到此页面的 collectionviewcell m 之一的 collectionview。
注意:我已经知道如何在两个视图控制器之间传递数据。但它在我的 case.Please 帮助中不起作用。
代码
@IBAction func StaffAtten_Action(_ sender: Any) {
// let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "StaffAttendence_SecondPage") as! StaffAttendence_SecondPage
//
// secondVC.a = active_text.text!
// secondVC.b = active_text.text!
// secondVC.c = active_text.text!
// secondVC.savedata.append(year.text!)
// secondVC.savedata.append(month.text!)
// secondVC.savedata.append(institute.text!)
}
}
您遇到的问题是您正在实例化一个全新的 VC 并将数据传递给它。实际呈现的VC不是您创建的
因为你有一个 segue 连接两个 VCs,覆盖 prepare(for:sender:)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? StaffAttendence_SecondPage {
vc.a = ...
vc.b = ...
// pass the rest of the data here...
}
}