UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
AllListsViewController *controller = navigationController.viewControllers[0];
controller.dataModel = _dataModel;
这是我以前的代码。我可以通过navigationController访问AllListsViewController,因为它是rootViewController。
但现在我的故事板发生了变化。我试图以同样的方式访问控制器,但它无法正常工作。
SWRevealViewController *revealViewController = (SWRevealViewController *)self.window.rootViewController;
UINavigationController *navigationController = (UINavigationController *)revealViewController.frontViewController;
AllListsViewController *controller = navigationController.viewControllers[0];
controller.dataModel = _dataModel;
也许是因为我在storyboard中设置了frontViewController,所以这个revealViewController.frontViewController是nil。但我不知道从AppDelegate.m访问它的其他方法。
抱歉,由于我的声誉,我无法发布任何图片。这是我的代码。https://github.com/liukaiyi54/CheckList
请有人帮帮我。我已经被这种折磨了好几天了。
提前致谢!
答案 0 :(得分:0)
试试这个:
//This is Main unless you have named your storyboard something different
UIStoryboard *storyBoard =[ UIStoryboard storyboardWithName:@"Main" bundle:nil];
//make sure to put this in "AllListsViewController" in your identifier in the storyboard
UINavigationController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"AllListsViewController"];
UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = myNavigationController;
这是您将故事板ID放在蓝框中的地方: