iOS-从AppDelegate导航到幻灯片菜单中的特定项目

我使用swrevealviewcontroller添加幻灯片菜单到我的应用程序,

在这里输入图像说明

让我们考虑我们有这样的菜单在图片我需要从我的appDelegate导航到菜单中的任何项目(例如:地图视图控制器)

我的尝试:

在我的appDelegate.m

UIStoryboard *storyboard =[UIStoryboard storyboardWithName:@"Main" bundle:nil]; InforView *school_view = [storyboard instantiateViewControllerWithIdentifier:@"info_view"]; [self.window makeKeyAndVisible]; [self.window.rootViewController presentViewController:school_view animated:YES completion:NULL]; 

当它转移到InforView控制器它崩溃在viewdidload

 - (void)viewDidLoad { [super viewDidLoad]; _nav_bar.target = self.revealViewController; _nav_bar.action = @selector(revealToggle:); // its crash here [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; } 

我的故事板

导航控制器 – >主视图 – >显示视图控制器

揭示View控制器有两个视图 – >滑动菜单导航控制器 – >前视图

我的幻灯片菜单中有一些项目出现在图片中

我需要从我的appDelegate导航到这些项目之一

在这里输入图像说明

最后我find答案

 UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; // this any item in list you want navigate to Home_tableView *home = (Home_tableView *) [storyboard instantiateViewControllerWithIdentifier:@"home_view"]; SlideMenu *slidemenu = (SlideMenu *)[storyboard instantiateViewControllerWithIdentifier:@"Menu_view"]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:home]; UINavigationController *smVC = [[UINavigationController alloc]initWithRootViewController:slidemenu]; // define rear and frontviewcontroller SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:smVC frontViewController:nav]; // make it as root self.window.rootViewController = revealController; 

在SidebarDemo项目中,您可以使用以下代码在初始加载时显示MapViewController。

 SWRevealViewController *revealViewController = (SWRevealViewController*)self.window.rootViewController; UIStoryboard *storyboard =[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; MapViewController *mapVC = [storyboard instantiateViewControllerWithIdentifier:@"MapID"]; [self.window makeKeyAndVisible]; UINavigationController* navController = (UINavigationController*)revealViewController.frontViewController; [navController setViewControllers: @[mapVC] animated: NO ]; [revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES]; 

makeKeyAndVisible之后,加载了revealViewController的frontViewController和realViewController。 您可以设置frontViewController的rootViewController,它是一个navigationController。