我使用自定义 XIB 文件作为视图控制器的弹出窗口。XIB 文件包含两个按钮 =“发送”和“添加附加字段”。选择添加其他字段的按钮会显示另一个嵌入在导航控制器中的视图控制器。当用户登陆该控制器屏幕并选择他们的额外选项时,该数据应传递回 XIB 的var extraOptions = [String]()
字段。从那里,用户应该能够通过选择“发送”来上传他们的帖子。
我遇到的问题是数据没有从嵌入在导航控制器中的视图控制器传回 XIB。
这甚至可能吗?我已经尝试了我能想到的所有解决方案:协议/委托方法,var extraOptions
在显示的控制器中设置XIB 文件中的字段,然后将其关闭并返回到 XIB,这是我的最新尝试:
名为CreatePostModal 的自定义 XIB (视图控制器是一个弹出窗口)
@objc func addExtraOptions(_ sender: UITapGestureRecognizer? = nil) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UINavigationController = storyboard.instantiateViewController(withIdentifier: "ExtraOptionsNavigationController") as! UINavigationController
vc.delegate = self
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
额外选项视图控制器
@IBAction func donePressed(_ sender: Any) {
if let navController = presentingViewController as? UINavigationController {
let presenter = navController.topViewController as! CreatePostModal
presenter.extraOptions = self.extraOptionsSelected
print("These are the options selected ==> \(present.extraOptions)") //this prints the options and shows that they're there, but the array is empty whenever a user tries to upload the data
}
dismiss(animated: true, completion: nil)
}
如您所见,在打印方法中,它打印变量并显示数据在那里,但是当返回 XIB 文件并且用户保存并上传数据时,该字段显示为空。
如何从嵌入在导航控制器中的视图将数据传回 XIB?
您可以通过以下三种方式使用其中之一:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句