MMDrawerController不是rootViewController

时间:2014-12-30 06:51:27

标签: ios rootview

我在我的项目中使用MMDrawerController,我不希望它成为rootViewController。我也使用故事板来设置UI。大多数示例代码都不像这样。所以我有点迷惑如何做到这一点。

我已经设置了一个嵌入了navigationController的FirstViewController,并且它上面有一个Button。 ButtonClick将控制器推送到CenterViewController。

这是我的代码......

FirstViewController.m

UIViewController * centerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
UIViewController * rightSideDrawerViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];

self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerViewController rightDrawerViewController:rightSideDrawerViewController];

[self.drawerController setShowsShadow:NO];
[self.drawerController setMaximumRightDrawerWidth:150.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

CenterViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
MMDrawerBarButtonItem * rightDrawerButton = [[MMDrawerBarButtonItem alloc] initWithTarget:self action:@selector(rightDrawerButtonPress:)];
[self.navigationItem setRightBarButtonItem:rightDrawerButton animated:YES];
}

-(void)rightDrawerButtonPress:(id)sender{
[self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}

RightViewController.m

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor yellowColor]; 
}

它无法正常工作。我是否应该在故事板中放置MMDrawerController?我很困惑。

1 个答案:

答案 0 :(得分:0)

您可以在应用程序中使用以下代码:didFinishLaunchingWithOptions:

application:didFinishLaunchingWithOptions但MMDrawerController仍然是你的根。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Home" bundle:nil];

UIViewController * leftSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
 @"LeftMenu"];

UIViewController * centerSideNavController = [storyboard instantiateViewControllerWithIdentifier : @"Home"];

UIViewController * rightSideNavController = [storyboard instantiateViewControllerWithIdentifier :
 @"RightMenu"];


UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerSideNavController];
self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:navigationController leftDrawerViewController:leftSideNavController rightDrawerViewController:rightSideNavController];



[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];


[self.window setRootViewController:self.drawerController];
/* Optional - To define Drawer width */
[self.drawerController setMaximumRightDrawerWidth:280.0];

[self.drawerController setMaximumLeftDrawerWidth:280.0];

[self.window makeKeyAndVisible];

希望这有帮助。