xcode 将导航控制器栏按钮与嵌入容器视图交互
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14580434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
interact the navigation controller bar button with embed container view
提问by Daniel Chen
I've created a UIViewController, and insert a container view in it, which embed a UITableViewController. As the image described above.
我创建了一个 UIViewController,并在其中插入了一个容器视图,其中嵌入了一个 UITableViewController。如上图所述。
When user click the Table View Cell, I'd like to add a UIBarButton on the Navigation bar.
当用户单击表格视图单元格时,我想在导航栏上添加一个 UIBarButton。
But, how can I manage this? I can rise the DatePicker when click on Table View Cell, but when I call self.presentingViewController in table view controller implementation file, it returns (null), same as when I call self.parentViewController
但是,我该如何管理呢?我可以在单击表视图单元格时升起 DatePicker,但是当我在表视图控制器实现文件中调用 self.presentingViewController 时,它返回(空),与调用 self.parentViewController 时相同
回答by rdelmar
You're probably trying to access the parent controller too early. If you log self.parentViewController in viewDidLoad, it will return null, but it should return the correct controller from viewDidAppear, and certainly from the didSelectRowAtIndexPath method. Using parentViewController in this context is correct, not presentingViewController.
您可能过早地尝试访问父控制器。如果你在 viewDidLoad 中记录 self.parentViewController,它将返回 null,但它应该从 viewDidAppear 返回正确的控制器,当然从 didSelectRowAtIndexPath 方法。在这个上下文中使用 parentViewController 是正确的,而不是presentingViewController。
回答by Maverick1st
I'd suggest to implement the UITableViewController Delegates and Datasource Methods in the ViewController itself. That way you don't have to worry about accessing the ViewController containing the UITableView.
我建议在 ViewController 本身中实现 UITableViewController Delegates 和 Datasource 方法。这样你就不必担心访问包含 UITableView 的 ViewController。