iPhone UINavigationController 应用程序设计

发布于 2024-09-13 10:14:54 字数 2077 浏览 2 评论 0原文

尝试着思考如何围绕 UINavigationController 构建应用程序。在我看来,大多数解释都假设应用程序总是从根控制器开始,并从那里向下钻取,但我不清楚这如何与进入应用程序之前发生的登录/注册步骤相适应。结构将是这样的:

 Home page                                            | Main app (typical nav hierarchy)
------------                                          |---------------------------------
 Log in   ----> Login page                            | App section 1
               ------------                           | App section 2
                Do login   ------------------------>  | etc.
             <- Cancel                                |
                                                      |
 Register ------------------->  Register page         |
                               -----------------      |
                                Do registration --->  |
                             <- Cancel                |

所以基本上我假设“主应用程序”控制器实际上应该是应用程序的根控制器,对吗?在这种情况下,我不清楚如何处理位于它前面的整个过程(基本上就像与应用程序导航结构分开的导航结构)。 “主页”是显示在主应用程序上的模式控制器,也是用于登录/注册步骤的单独导航控制器,以便在登录后简单地弹出它以将我们带回应用程序根目录?

希望我只是把一件真正简单的事情复杂化了,只是似乎还没有适合我。任何指示都非常感激。

编辑:这就是我最终得到的结果,它似乎适合我的需要。我有两个 UINavigationController,它们都分配给 IB 中的 MainWindow,并具有单独的启动 NIB。一个是应用程序启动导航控制器(主页/登录/注册),另一个是主应用程序导航控制器。我的应用程序委托有以下代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [window addSubview:startNavController.view];
    [window makeKeyAndVisible];
    return YES;
}

- (void)activateMainApp {
    [startNavController.view removeFromSuperview];
    [window addSubview:appNavController.view];
    [window makeKeyAndVisible];
}

在登录/注册的最后一步中,我有这段代码,它调用应用程序委托以在导航控制器之间进行切换:

- (IBAction)continuePressed {
    // Transfer control to the main app nav controller:
    MyAppDelegate *app = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
    [app activateMainApp];
    [app release];
}

我怀疑我可以使用一个导航控制器来完成此操作,但是这个根据我的视图结构,这对我来说具有逻辑意义并且似乎有效,并且我最终根据需要将主主页视图作为应用程序导航控制器的根视图。如果有什么愚蠢的事情,任何额外的反馈都会受到赞赏。

Trying to wrap my head around how to structure an app around the UINavigationController. It seems to me that most explanations assume that the app always starts off at the root controller and drills down from there, but I'm unclear as to how this fits in with a login/registration step that happens before you get into the app. The structure will be like this:

 Home page                                            | Main app (typical nav hierarchy)
------------                                          |---------------------------------
 Log in   ----> Login page                            | App section 1
               ------------                           | App section 2
                Do login   ------------------------>  | etc.
             <- Cancel                                |
                                                      |
 Register ------------------->  Register page         |
                               -----------------      |
                                Do registration --->  |
                             <- Cancel                |

So basically I'm assuming that the "Main app" controller should actually be the root controller of the application, correct? In which case I'm unclear on how to handle the whole process that sits in front of it (which is basically like a nav structure separate from the app nav structure). Is the "Home page" a modal controller displayed over the main app, and also a separate nav controller for the login/register steps, so that it simply gets popped after login to put us back at the app root?

Hopefully I'm just overcomplicating what is really a simple thing, just hasn't seemed to click for me yet. Any pointers greatly appreciated.

EDIT: So here's what I ended up with, which seems to work for what I need. I have two UINavigationControllers, both assigned to the MainWindow in IB with separate starting NIBs. One is the app startup nav controller (home/login/registration) and the other is the main app nav controller. My app delegate has this code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [window addSubview:startNavController.view];
    [window makeKeyAndVisible];
    return YES;
}

- (void)activateMainApp {
    [startNavController.view removeFromSuperview];
    [window addSubview:appNavController.view];
    [window makeKeyAndVisible];
}

In the last step of login/registration, I have this code that is what calls the app delegate to make the switch between nav controllers:

- (IBAction)continuePressed {
    // Transfer control to the main app nav controller:
    MyAppDelegate *app = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
    [app activateMainApp];
    [app release];
}

I suspect that I could have accomplished this with one nav controller, but this made logical sense to me based on my view structure and seems to work, and I end up with the main home view as the app nav controller's root view, as desired. Any additional feedback is appreciated if there's something bone-headed about this.

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

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

发布评论

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

评论(2

离笑几人歌 2024-09-20 10:14:54

您可以在任何阶段创建 UINavigationController,包括在登录屏幕之后 - 只需将其设为您要开始使用它的视图的子视图即可。此时您将看到视图控制器(您将其作为新导航控制器的根视图)。拥有它后,您可以将新的视图控制器推送到导航堆栈上。您可以查看导航堆栈

根控制器没有什么特别之处,除了您可以通过一次调用 (popToRootViewControllerAnimated) 到达那里,并且您无法弹出更远的位置。导航控制器管理的所有视图控制器都位于堆栈上,因此您可以根据需要压入堆栈或从堆栈中弹出。

我认为当后退箭头有用时它就很有用。

You can create a UINavigationController at any stage, including after your login screen - just make it a subview of the view you want to start using it on. You will see the view controller (which you made the root view of the new nav controller) at that point. Once you have it you can push new view controllers onto the navigation stack. You can look at the navigation stack

There is nothing really special about the root controller except that you can get there in one call (popToRootViewControllerAnimated) and that you can't pop further than that. All of the view controllers managed by the navigation controller are just on a stack so you can push onto the stack or pop off the stack as you like.

I think of it as a thing that is useful when the Back arrow will be useful.

望喜 2024-09-20 10:14:54

UINavigationController 实际上只是组织 UIViewController 的一种方式。不必有特定的根视图。您只需将您想要的视图放在上面即可。

要在顶部添加另一个视图控制器,只需调用 [UINavigationController PushViewController:animated:YES];

UINavigationController is really just a way to organize UIViewControllers. There doesn't have to be a specific root view. You just put the views you want on top.

To add another view controller on top just call [UINavigationController pushViewController: animated:YES];

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