【发布时间】:2014-03-28 17:51:36
【问题描述】:
我的应用由导航控制器和视图控制器组成。我的 UI 的某些部分是在情节提要上完成的,而有些部分是从代码启动的(在 viewDidLoad 中)。我的目标是通过 appDelegate 中的此方法从推送通知“正确”启动应用程序时加载 childViewController X(由后退按钮、导航栏、标签和表格组成):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
这对你们来说可能是一个简单的问题,但几天来我已经问了几个问题(您可以查看我的问题历史记录)。在尝试了几种方法后,我的应用要么:
崩溃 加载没有导航栏 加载导航栏但没有标签(后退按钮不起作用) 加载导航栏但下方有黑屏 只有 tableView 被拖到故事板上。导航栏是推断出来的,但我有指示其后退按钮和标题的代码。其余的都是通过 .m 文件中的代码完成的。
我知道以前有人问过这个问题,但没有一种方法奏效。如何通过推送通知正确加载此 childViewController?
到目前为止我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController* firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:@"NotificationsViewController"];
[self.window.rootViewController addChildViewController:firstVC];
[(UINavigationController *)self.window.rootViewController pushViewController:firstVC animated:NO];
self.window.rootViewController.childViewControllers);
}}
错误代码:
'-[SWRevealViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14575f20'
SWRevealViewController 是我的侧边栏菜单视图控制器库。
这个方法我也试过了:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:@"NotificationsViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
这会加载正确的 viewController 但没有导航栏。
【问题讨论】:
标签: ios objective-c navigation initialization appdelegate