如何使用 Storyboard 在 AppDelegate 中使用自定义 Navigationcontroller [英] How to use custom Navigationcontroller in AppDelegate by using a Storyboard

查看:24
本文介绍了如何使用 Storyboard 在 AppDelegate 中使用自定义 Navigationcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 AppDelegate 中遇到了关于 Navigationcontroller 的问题.我正在使用一个故事板,它看起来像这样:

I've got a problem concerning Navigationcontroller in AppDelegate. I'm using a storyboard, which looks like this:

由于使用推送通知,我的 AppDelegate 文件中有以下功能:

As a result of using Push notifications, i've got the following function in my AppDelegate File:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
//...
}

当通知到达时,我想初始化Detail View"——需要一个 ID 作为参数的控制器.此 ID 是我的有效负载的一部分,因此它存在于 didReceiveRemoteNotification 中.

When the notification arrives I want to initialize the "Detail View" - Controller which needs an ID as a parameter. This ID is part of my payload so it is present in didReceiveRemoteNotification.

我想了解以下内容:

DetailView *detail = [storyboard instantiateViewControllerWithIdentifier:@"detail"];

detail.conversationID = theID; 

[self.navigationController pushViewController:detail animated:YES];

此时我的问题是:我怎样才能获得导航控制器?我搜索了像getNavigationControllerByIdentifier"之类的函数或类似的东西,但一无所获.我无法直接实例化 Detail View Controller,因为那里缺少导航栏.

My question at this point is: how can I get the navigation controller? I've searched for a function like "getNavigationControllerByIdentifier" or something like this, but found nothing. I can't instantiate the Detail View Controller directly because the navigationbar is missing there.

我希望你明白我的意思——如果你认为我的方法完全错误,请纠正我;o)

I hope you understand what I mean - if you think my approach is completly wrong please correct me ;o)

还有一个小信息:细节视图控制器中的后退按钮返回到表视图对我来说并不重要 - 当它通过加载表视图"按钮链接到控制器时就足够了.

Just another small information: It's not important for me that the back button in the Detail View Controller goes back to the Table View - it's enough when it links to the controller with the button "Load Table View".

感谢您的帮助!

推荐答案

UINavigationController 是一个 UIViewController 子类,也可以在故事板中分配一个标识符.

UINavigationController is a UIViewController subclass and can also be assigned an identifier in the storyboard.

使用 -instantiateViewControllerWithIdentifier: 创建 UINavigationController 和它的根视图控制器.您可能需要在代码中实例化所有中间控制器并修改导航控制器的 viewControllers 属性以设置适当的导航堆栈.这样,当应用程序启动到详细信息视图时,他们可以找到返回的路,就好像他们已经通过界面手动一直推过去一样.

Use -instantiateViewControllerWithIdentifier: to create the UINavigationController and it's root view controller. You may need to instantiate all of the intermediate controllers in code and modify the navigation controller's viewControllers property to set up the appropriate navigation stack. This way when the app launches into the detail view, they can find their way back as if they had manually pushed all the way through via the interface.

这篇关于如何使用 Storyboard 在 AppDelegate 中使用自定义 Navigationcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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