UINavigationController直接转到“下一个"控制器? [英] UINavigationController going directly to 'next' controller?

查看:60
本文介绍了UINavigationController直接转到“下一个"控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UINavigationController,它具有3个层次的层次结构:菜单->子菜单->详细信息.Menu和Submenu是UITableViews,而Details是一些自定义视图控制器.

I have a UINavigationController with 3 levels of hierarchy: Menu->Submenu->Details. Menu and Submenu are UITableViews whereas Details is some custom view controller.

我想在详细信息"视图中添加上一个"和下一个"按钮,使我可以直接转到当前子菜单中的上一个和下一个项目.

I want to add 'previous' and 'next' buttons in the Details view that will allow me to directly go to the previous and next items from the current Submenu.

例如,假设我有:

|Menu    |M1 Submenu |SM2 Details
--------------------------------
M1  ->   |SM1        |D1
M2       |SM2   ->   |D2
M3       |SM3        |D3  // Let's say we are here now
                     |D4
// ... etc ...

// The arrows represent items the user selected

因此,假设该应用当前正在显示"D3详细信息"视图控制器.这意味着我们当前位于M1-> SM2-> D3中.现在在D3中,如果用户按下下一步"按钮,则应显示D4.同样,如果他/她按下上一个"按钮,则应显示D2.

So let's say the app is currently showing the D3 Details view controller. This means that we are currently in M1->SM2->D3. Now in D3 if the user presses a 'next' button it should show D4. Similarly if s/he presses the 'previous' button it should show D2.

因此,下一个"和上一个"按钮在本质上与按导航控制器的后退"按钮,然后选择列表中的下一项相同.

So the 'next' and 'previous' buttons essentially do the same thing as pressing the navigation controller back button and then selecting the next item in the list.

实现此目标的最佳方法是什么?我是否必须跳回到子菜单,然后按另一个Details控制器?我是否可以直接从详细信息视图控制器中调用子菜单控制器(如果是,如何调用)?

What would be the best way to implement this? Do I have to pop back up to the submenu and then push another Details controller? Do I call the submenu controller directly from the details view controller (if so how)?

谢谢.

推荐答案

实际上不需要调用父控制器.这是您可以做的:

There's really no need to call the parent controller. Here's what you can do:

假设您在Submenu Controller中保留了一个细节"项的数组,而不是使用所选项初始化详细信息控制器,而是使用数组和所选索引对其进行了初始化.

Assuming you keep an array of "detail" items in Submenu Controller, instead of initializing the detail controller with the selected item, initialize it with the array and the selected index.

然后,当按下上一个/下一个按钮时,更改所选索引并相应地更新视图.

Then, when the prev/next buttons are pressed, change the selected index and update the view accordingly.

这篇关于UINavigationController直接转到“下一个"控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆