我正在尝试将数据从弹出视图发送到DataView . 它确实有效! . 但是,当我返回弹出视图编辑文本时,它不会显示输入并发送到DataView的文本 .
我正在通过协议发送数据 .
PopupView
protocol DataEnteredDelegate: class {
func userDidEnterInformation(data: String)}
@IBAction func DoneButton(_ sender: Any) {
if let data = openTextView.text {
delegate?.userDidEnterInformation(data: data)
self.dismiss(animated: true, completion: nil)
}
}
数据视图
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "openSummary" {
let sendingVC: popupViewController = segue.destination as! popupViewController
sendingVC.delegate = self
}
}
// Protocol receving data from popup
func userDidEnterInformation(data: String) {
addJobSum.text = data
}
1 回答
在PopupViewController被解除后,它被破坏,并且没有新实例能够知道旧实例具有的文本视图的文本值 .
要修复它 - 在
PopupViewController
中创建一个字符串属性,并在某些方法中初始化Text View的text属性及其值,例如viewDidLoad()
:然后,你必须在
prepare(for:)
方法内(在它出现之前)为textData
注入正确/需要的文本: