2016-09-07 15 views
0

我想實現MMDrawer實現左側抽屜,但只在一個視圖控制器中,它不是根控制器。 在登錄按鈕的點擊我應該能夠重定向到另一個視圖控制器不捨抽屜和中心視圖在現有的導航控制器中使用MMDrawer

幾乎類似的問題Using MMDrawer only in sub navigation view

-(void) signInButtonListener:(UIButton *)button{ 

    UIViewController * leftDrawer = [[leftDrawerViewController alloc] init]; 
    UIViewController * center = [[centreViewController alloc] init]; 

    MMDrawerController * drawerController = [[MMDrawerController alloc] 
         initWithCenterViewController:center 
         leftDrawerViewController:leftDrawer 
         rightDrawerViewController:nil]; 

[drawerController setShowsShadow:NO]; 
[drawerController setRestorationIdentifier:@"MMDrawer"]; 
[drawerController setMaximumRightDrawerWidth:200.0]; 
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll]; 
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll]; 

[drawerController 
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) { 
    MMDrawerControllerDrawerVisualStateBlock block; 
    block = [[MMExampleDrawerVisualStateManager sharedManager] 
       drawerVisualStateBlockForDrawerSide:drawerSide]; 
    if(block){ 
     block(drawerController, drawerSide, percentVisible); 
    } 
}]; 

landingPageViewController *landingPageController = [UBNLandingPageViewController new]; 
[myNavigator pushViewController:drawerController animated:YES]; 
} 

回答

0

在AppDelegate.h

@property (strong, nonatomic) MMDrawerController *drawer; 

在AppDelegate.m文件中 裏面:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 




UIStoryboard *mainstory=[UIStoryboard storyboardWithName:@"Main" bundle:nil]; 

UIViewController * leftDrawer = [mainstory instantiateViewControllerWithIdentifier:@"MenuTableViewController"]; 

     UIViewController * center = [mainstory instantiateViewControllerWithIdentifier:@"HomeViewController"]; 

    UINavigationController *leftnav=[[UINavigationController alloc]initWithRootViewController:leftDrawer]; 
     UINavigationController *homnav=[[UINavigationController alloc]initWithRootViewController:center]; 
//drawer is the object for MMDrawerController 
drawer=[[MMDrawerController alloc]initWithCenterViewController:homnav leftDrawerViewController:leftnav rightDrawerViewController:nil]; 

//不寫

_window.rootViewController = drawController; [_window makeKeyAndVisible]; 評論這些行,如果你寫。

在烏爾LoginButtonAction

進口AppDelegate.h文件,並寫入這些行內則U將得到中心視圖作爲下一個頁面。

AppDelegate *app=(AppDelegate *)[[UIApplication sharedApplication]delegate]; 
    app.window.rootViewController = app.drawer; 
    [app.window makeKeyAndVisible];