我有几个委托(delegate)已经在我的代码中工作了(不问如何使用它们)。我在从父 ViewController( Storyboard中的 More Information
属于类 InputViewController
)获取数据到子 TableViewController(AddressTableViewController
)时遇到问题) 因为我无法从此类引用父 Controller 。
TableViewController 和 map 都在 InputViewController
中。我想将数据(来自 locationManager 的反向地理定位地址)从 map 发送到 AddressTableViewController
以填充单元格文本。 TableViewControllers 通过对象(在对象库中选择)绑定(bind)到 InputViewController
(主 Controller )。
代码:https://gist.github.com/damionjn/c148a07a39b5c27e7f78
你会看到我在这里尝试使用 InputViewController
底部的协议(protocol):
https://gist.github.com/damionjn/c148a07a39b5c27e7f78#file-gistfile1-swift-L125
但我无法使用它,因为我无权访问 InputViewController
,因此 mapAddressDataSource
始终为 nil
。我已经尝试在 AddressTableViewController
的 init()
中创建它的一个实例并创建一个 IBOutlet,但没有任何运气。
最佳答案
I'm having a problem getting data from the parent ViewController (More Information in the storyboard belongs to class InputViewController) to the child TableViewController (AddressTableViewController) as I'm unable to reference the parent controller from this class.
为什么不呢?
在 AddressTableViewController
上为您的 InputViewController
创建一个属性,但将其创建为 weak 并且您可以访问它而不会导致任何问题(保留循环)。
例如
@property (weak, nonatomic) InputViewController *parentInputViewcontroller;
然后您应该能够从您的 tableView 子类中访问 self.parentInputViewController
上的任何数据。
关于ios - 通过对象将数据从父 ViewController 传递到子 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30496693/