iPhone从子视图访问导航控制器

发布于 2024-11-06 14:30:46 字数 857 浏览 8 评论 0原文

我有一个加载表格视图的导航控制器,从这里用户可以选择一行来加载被推入堆栈的详细视图。这个详细视图控制器在底部栏中有一个分段控件,它使用 [self.view insertSubview:firstDetailViewController.view atIndex:0] 加载一系列视图;等等...

这工作正常 - 加载的子视图之一还包含一个加载另一个详细视图的表。这导致了问题,因为我无法从子视图中访问导航控制器。为此,我必须使用:

YourAppDelegate *del = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:nextViewController animated:YES];

我在这里找到的: 从子视图导航控制器访问顶部导航控制器

但还有另一种情况需要类似的功能。从主视图控制器加载列表视图并以模态方式呈现。从这里我使用 self.navigationController 等将 2 个详细视图推送到这个新的导航堆栈上...效果很好。但是,当子视图尝试推送详细信息视图时,它不起作用。 self.navigationController 不起作用,appDelegate 将它们推送到另一个导航控制器上,而 self.parentViewController.navigationController 不起作用。

有什么想法吗?

I have a navigation controller that loads a tableview, from here the user can select a row which loads a detail view that gets pushed onto the stack. This detail view controller has a segmented control in the bottom bar which loads in a series of views using [self.view insertSubview:firstDetailViewController.view atIndex:0]; etc...

That works fine - one of the subviews loaded also contains a table which loads another detail view. This caused problems because I couldn't access the navigation controller from within the sub view. To do so I had to use:

YourAppDelegate *del = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:nextViewController animated:YES];

Which I found here: Accessing a Top Navigation Controller from a Subview Navigation Controller.

But there's another instance where similar functionality is required. From the home view controller a lists view is loaded and presented modally. From here I push 2 detail views onto this new navigation stack using self.navigationController etc... which works fine. But when the subview tries to push the detail view it doesn't work. self.navigationController doesn't work, the appDelegate one pushes them onto the other nav controller and self.parentViewController.navigationController doesnt work.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2024-11-13 14:30:46

所以你的 Home VC 确实呈现了表视图的 ModalVC。表视图执行 self.NavCon PushVC: 详细信息。然后细节无法推送子细节。是这样的场景吗?

我想知道 tableview 从哪里获得它的导航控制器,因为它是模态呈现的,不需要 NavCon。

我还想知道您是否可以将表格视图推到 NavCon 上,而不是以模态方式呈现;那么细节应该有一个完整的 NavCon,然后可以依次推送子细节。

希望有帮助。
-麦克风

So your Home VC does presentModalVC of a table view. The table view does a self.NavCon pushVC: detail. And the detail then fails to push a sub-detail. Is that the scenario?

I'm wondering where the tableview got it's nav controller from, since it was presented modally, which does not require a NavCon.

I'm also wondering if you could push the tableview onto the NavCon instead of presenting modally; then the detail should have an intact NavCon which could then in turn push a sub-detail.

Hope that helps.
-Mike

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文