【发布时间】:2017-08-20 12:23:41
【问题描述】:
我有 1 个 UIViewController,其中包含一个 UIContainerView 和一个 UIButton。 另外,我有一个嵌入在 UIViewController 的 UIContainerView 中的 UITableViewController(它有一个 UITextField 和一个 UITextView)。
我正在尝试获取将在 TextField 和 TextView 中可用的字符串值。
我尝试使用 segue 来获取属性值,但我没有这样做,请参阅下面的代码。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "TVCSegue" {
let containerTVC = segue.destination as? FieldsTVC
self.textField.text = FieldsTVC?.textField?.text
self.textView.text = FieldsTVC?.textView?.text
}
}
上面的代码在 UIViewController 中有 'textField' 和 'textView' 作为属性来分配值。
但我相信它不起作用,因为我在值改变之前就得到了它们。请为我提供一种实用的方法。
【问题讨论】:
-
分享您的代码,因为 segue 是最简单且可行的方法。
-
信息太少。您提到了一个 UITableViewController 与另一个带有字段的 UIViewController 相连接,这并没有反映上图。
-
@GiorgioR。我已经用更多细节编辑了这个问题。
-
@KrunalBhavsar 请检查我已编辑的问题。
-
目前还不清楚,但我至少看到两个问题:1.您分配的值(文本)不是从对象(containerTVC)而是从相关类型(FieldsVC)中检索它们; 2.你是在执行segue之前分配值(即:就在去另一个场景之前),所以即使它们被分配了,你会如何看待它们?
标签: ios swift uicontainerview