iOS- navigate From AppDelegate to certain item in slidemenu

≡放荡痞女 提交于 2020-01-25 06:20:55

问题


I use swrevealviewcontroller to add slide menu to my app ,

Let consider we have menu like this one in pic I need navigate from My appDelegate to any item in menu (ex:Map View Controller )

my tries :

in my 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];

When its move to InforView Controller it crash in viewdidload

- (void)viewDidLoad
{
    [super viewDidLoad];
    _nav_bar.target = self.revealViewController;
    _nav_bar.action = @selector(revealToggle:);

 // its crash here 
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}

my storyboard

navigation controller --> home view --> reveal View controller

reveal View controller has two views --> slide menu navigation controller -- > Front view

my slide menu has some items as appear in pic

I need navigate from my appDelegate to one of this items


回答1:


Finally I find the answer

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;



回答2:


In the SidebarDemo project, you can use the following code to show MapViewController on initial loading.

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];

After makeKeyAndVisible, the frontViewController and realViewController of the revealViewController are loaded. And you can set rootViewController of frontViewController, which is a navigationController.



来源:https://stackoverflow.com/questions/28067352/ios-navigate-from-appdelegate-to-certain-item-in-slidemenu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!