iOS-导航从AppDelegate到slidemenu中的某个项目

时间:2015-01-21 12:32:56

标签: ios objective-c swrevealviewcontroller

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

enter image description here

让我们考虑在pic中有这样的菜单 我需要从My appDelegate导航到菜单中的任何项目(例如:Map View Controller)

我的尝试:

在我的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];
}
  

我的故事板

导航控制器 - >主页视图 - >显示视图控制器

显示视图控制器有两个视图 - >幻灯片菜单 导航控制器 - >前视图

我的幻灯片菜单中有一些项目显示在图片

我需要从我的appDelegate导航到其中一个

enter image description here

2 个答案:

答案 0 :(得分:3)

最后我找到了答案

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;

答案 1 :(得分:0)

在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。