我有一个 UIViewController,它有另一个 UITableViewController 作为 subview 。
表格 View 是不可见的,但有时它可以通过用户的操作看到。 (例如,搜索 TableView 。)
所以,两个新 Controller 实际上没有关系,(但 UIViewController 有 UITableViewController 作为成员变量),但只有它的 View 有父 - subview 关系。
在这种情况下,用户单击表格 View 中的单元格项目,我必须将新的 View Controller 推送到导航 Controller 。
但只有父 UIViewController 在 navigationController 中, subview UITableViewController 没有。
代码
[self pushViewController:viewController animated:YES];
在 UITableViewController 中失败。
我通过将父 UIViewController 的 navigationController 实例作为名为 parentNavigationController 的属性传递给 UITableViewController 解决了这个问题,我调用了
[self.parentNavigationController pushViewController:viewController animated:YES];
相反。
这个解决方案还算不错,但是我觉得有点乱,想知道有没有更清晰的解决方案。
在这种情况下你是如何编程的, friend 们?
首先,我认为两个 View Controller 的父 subview 关系很困惑。如果我在一个 viewController 中管理两个 View 会更好吗?那么,UITableViewController 的view 属性可以不是table view 吗? (并且该 View 具有 TableView 作为 subview )
提前感谢您的支持。
最佳答案
实际上这个概念是将 View Controller 推送到导航 Controller 的导航堆栈。 UIViewControllers 只能呈现模态视图 Controller ,它们不能推送 View Controller 。因此,向 self(这是一个 UIViewController)发送 pushViewController 消息是错误的。您可以使用 [self.navigationController pushViewController:anotherViewController];
关于iphone - 如何设置 subview-viewController 的 navigationController 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6561666/