将子视图添加到 UINavigationController 然后返回第一个子视图?
我有一个基于导航的应用程序,其中我将 ABPeoplePickerNavigationController 作为子视图添加到我的导航控制器中,如下所示: 在将子视图添加到 navView 之前,我已经保存了视图。
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
navView = [[UIView alloc] init];
navView = [[self.view superview] superview];
[[[self.view superview] superview] addSubview:[peoplePicker view]];
它工作正常,但是当我完成 PeoplePicker 后,我想返回到之前的视图。我使用了这段代码,但它不起作用。
[[[self.view superview] superview] addSubview:navView];
我不明白,我已经从子视图中保存了 navView,现在我无法将其恢复?
I have a Navigation-Based app in which i added ABPeoplePickerNavigationController as a subview to my Navigation Contorller like this:
I have saved the view before adding subview into navView
.
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.peoplePickerDelegate = self;
navView = [[UIView alloc] init];
navView = [[self.view superview] superview];
[[[self.view superview] superview] addSubview:[peoplePicker view]];
It works fine, but when I'm done with the PeoplePicker and I want to get back to the previous view. I used this code but it doesn't work.
[[[self.view superview] superview] addSubview:navView];
I don't get it, I have saved the navView from the subview, now I can't bring it back?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要添加后退按钮,如下所示:
理想情况下,您的 NavigationController 是应用程序的根,在这种情况下,任何其他视图都是它的子视图,因此您永远不会真正离开导航控制器,您只需更改实际的视图即可显示。
此外,您尝试引用第一个视图的方式相当混乱/令人困惑。您应该将其更改为类似以下内容:
或者
我无法确定要使用哪个,因为我不确定您的确切视图层次结构,但我强烈建议您尝试优化该代码。
我可能应该注意到导航控制器上的后退按钮和下面的两行执行不同的操作。后退按钮返回一个视图,而 popToRoot 和 topView 都旨在将您带回到第一个 viewController。
编辑:将后退按钮代码更改为我实际使用的代码
编辑2:只是因为我在这里有更多的空间,我可以尝试更好地理解您的层次结构。看起来像这样?
这意味着 ABPeoplePicker 嵌套在 Group 中,并且嵌套在您的根中?我认为它不起作用,因为你实际拥有的是第一行中的两个之一,而你想要的是第二行。因为我实际上不知道你没有看到它,所以我无法确切地告诉你要更改什么,但是如果你希望它像第二行的层次结构一样一直嵌套,你需要推送你的组视图到根视图控制器(这是您的导航控制器),然后您想再次将人员选择器推到根视图控制器上。之后,您的后退按钮和视图切换应该按照您想要的方式工作。
You need to add the back button, like so:
Ideally your NavigationController is the root of your application, in which case any other view is a subview of it so you never trully swich away from your navigation controller, you merely change the actual view that is shown.
Also the way in which you attempt to reference your first view is fairly messy/confusing. You should change it to something like:
or
I cant tell you for certain which to use as I am not sure of your exact view hierarchy, but I would highly recommend that you try to optimize that code.
I should probably note that the back button on the navigation controller and the the two lines below that do different things. The back button returns you one view back, while popToRoot and topView are both intended to bring you back to the very first viewController.
Edit: Changed the back button code to the code I actually use
Edit2: Just because I have a bit more space here I can try to understand your heirarchy better. It looks something like this?
Meaning that ABPeoplePicker is nested within Group, and that is nested within your root? I think that its not working because what you actually have is one of the two on the first line, when what you want is the second line. Because I don't actually know which one you have without seeing it, I cant tell you exactly what to change, but if you want it to be nested all the way like the heirarchy on the second line, you need to push your group view onto the root view controller(Which is your navigation controller), then you want to push People Picker onto the root view controller again. After this your back button and view switching should be working the way you want it to.