MMDrawerController Library to work with storyboard - ios

So I've recently come across this pretty neat library, MMDrawerController. I've managed to install it and initialized it with the code below in appDelegate.m.
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIViewController * leftSideDrawerViewController = [[LeftViewController alloc] init];
UIViewController * centerViewController = [[CenterViewController alloc] init];
UIViewController * rightSideDrawerViewController = [[RightViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[navigationController setRestorationIdentifier:#"MMExampleCenterNavigationControllerRestorationKey"];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:rightSideDrawerViewController];
[self.drawerController setRestorationIdentifier:#"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:200.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.drawerController];
return YES;
}
However, everything in my storyboard is now covered in black (caused by the code above "overriding" storyboard's xml code)when I build the app. How can I properly integrate this library along with storyboard?

Following is what needs to be done:-
1) Create 3 Views in your Storyboard and give both Class and Storyboard ID to each of them.
2) Embed your Centre View Controller in Navigation Controller i.e. Click on your Centre view and then click on "Editor" => "Embed In" => "Navigation Controller"
3) Go to following github link:-
https://github.com/mutualmobile/MMDrawerController
and download file MMDrawerController Zip file from there.
4) Include following files from above github project to your project by right clicking your project and choosing "Add Files to " :-
MMExampleDrawerVisualStateManager.h
MMExampleDrawerVisualStateManager.m
MMDrawerBarButtonItem.h
MMDrawerBarButtonItem.m
MMDrawerController.h
MMDrawerController.m
MMDrawerController+Subclass.h
MMDrawerVisualState.h
MMDrawerVisualState.m
UIViewController+MMDrawerController.h
UIViewController+MMDrawerController.m
5) Finally go to AppDelegate.m file and within didFinishLaunchingWithOptions function type following code:-
Objective-C
UIStoryboard *storyboard;
storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * leftSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
#"leftViewController"];
UIViewController * centerSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
#"ViewController"];
UIViewController * rightSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
#"rightViewController"];
self.drawerController =
[[MMDrawerController alloc]
initWithCenterViewController:centerSideNavController
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];
Swift 2.2
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let centerVC = mainStoryBoard.instantiateViewControllerWithIdentifier("Home") as! HomeVC
let leftVCs = mainStoryBoard.instantiateViewControllerWithIdentifier("Left") as! LeftVC
let rightVCs = mainStoryBoard.instantiateViewControllerWithIdentifier("Right") as! RightVC
let rightSideNav = UINavigationController(rootViewController: rightVCs)
let leftSideNav = UINavigationController(rootViewController: leftVCs)
let centerSideNav = UINavigationController(rootViewController: centerVC)
centerContainer = MMDrawerController(centerViewController: centerSideNav, leftDrawerViewController: leftSideNav, rightDrawerViewController: rightSideNav)
centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView
centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView
centerContainer?.setDrawerVisualStateBlock(MMDrawerVisualState.swingingDoorVisualStateBlock())
window!.rootViewController = centerContainer
window!.makeKeyAndVisible()
Note: Add var centerContainer: MMDrawerController? within AppDelegate class globally in case of Swift version.

if you want drawer in storyboard than used this library i already used in many projects Drawer.

Have a look on this, https://github.com/TomSwift/MMDrawerController-Storyboard
Its a category for MMDrawerController works like a charm with storyboard!

Just an addition to Meet Shah's answer, If some one is missing navigation bar in center controller then just add a below code in between his code
UINavigationController * navigationController = [[UINavigationController alloc]
initWithRootViewController:centerSideNavController];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideNavController
rightDrawerViewController:rightSideNavController];
hope that helps some one.

Related

SWRevealViewController not able to call from the appdelegate.m

I am calling SWRevealViewController in Appdelegate.m
SWRevealViewController *svc = self.revealViewController;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
FrontVC *homeVC = [storyboard instantiateViewControllerWithIdentifier:#"FrontVC"];
[svc setFrontViewController:homeVC animated:NO];
[svc revealToggleAnimated:YES];
But i am not able to load FrontVC controlller .
what is right way to call
For Swift 2.2
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController
self.window?.rootViewController = sw
let cv = storyboard.instantiateViewControllerWithIdentifier("IDOFCONTROLLER") as! NAMEOFCONTROLLER
let navigationController = UINavigationController(rootViewController: cv)
sw.pushFrontViewController(navigationController, animated: true)
I hope this one helps.
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// this any item in list you want navigate to
yourHomeViewController *home = (yourHomeViewController *) [storyboard instantiateViewControllerWithIdentifier:#"leid"];
yourSideMenuViewController *slidemenu = (yourSideMenuViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MenuView"];
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;
We can't call RevealViewController in App Delegate.
You can directly add this in Your ViewController for Front & rear.
Have you declared and initialized revealViewController anything like this?
#interface AppDelegate ()
#property (strong, nonatomic) SWRevealViewController *revealViewController;
#end
/* ... */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.revealViewController = /* ... init ... */;
/* ... your code here ... */
}
I didn't use a storyboard but did it like this:
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:menuViewController frontViewController:frontNavigationController];
SWRevealViewController *viewController = revealController;
I think u can put the start indicator in the SWRevealViewController in ur storyboard, give the login VC a name
//if user is logged in - In login VC
[[NSUserDefaults standardUserDefaults] setValue:1 forKey:isLogged];
//In Appdelegate
if([[NSUserDefaults standardUserDefaults] valueForKey:isLogged] == 1)
{
NSLog(#"have data");
//Start straight into normal SWRevealVC
self.window.rootViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
}
else
{
//If not, make your root VC the login viewcontroller
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"LoginViewController"];
self.window.rootViewController = rootController;
}

MMDrawerController not rootViewController

I'm using MMDrawerController in my project and I don't want it to be the rootViewController. Also I'm using storyboard to set the UI. Most sample code doesn't present like this. So I'm a little confuse how to do it.
I've set a FirstViewController embed with navigationController and there is a Button on it. ButtonClick push the controller to CenterViewController.
Here is my code...
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];
}
It can't work. I'm confuse whether should I put a MMDrawerController in storyboard?
you can use following code in application:didFinishLaunchingWithOptions:
application:didFinishLaunchingWithOptions but still MMDrawerController will be your root.
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];
Hope this helps.

MMDrawerController instantiation

I'm trying to use the MMDrawerController in my app. I've downloaded the source and the dependencies. This is the code that I've added to the AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIViewController * leftDrawer = [[UIViewController alloc] init];
UIViewController * center = [[UIViewController alloc] init];
UIViewController * rightDrawer = [[UIViewController alloc] init];
MMDrawerController * drawerController = [[MMDrawerController alloc]
initWithCenterViewController:center
leftDrawerViewController:leftDrawer
rightDrawerViewController:rightDrawer];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:center];
[navigationController setRestorationIdentifier:#"MMExampleCenterNavigationControllerRestorationKey"];
[self.drawerController setRestorationIdentifier:#"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:200.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
UIViewController * sideDrawerViewController;
if(drawerSide == MMDrawerSideLeft){
sideDrawerViewController = drawerController.leftDrawerViewController;
}
else if(drawerSide == MMDrawerSideRight){
sideDrawerViewController = drawerController.rightDrawerViewController;
}
[sideDrawerViewController.view setAlpha:percentVisible];
}];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:self.drawerController];
return YES;
}
However the app runs to a blank screen.What am I missing?
UINavigationController * navigationController =
[[UINavigationController alloc] initWithRootViewController:drawerController];
[self.window setRootViewController:navigationController];
and no need to write below line:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Hope this will perfectly work.
Replace the line of code before return with the following
[self.window setRootViewController:navigationController];
Your problem is that you are setting the center, right and left views with UIViewController and also these UIViewControllers settings are not defined
in order to integrate the MMDrawerController right do the following.
In order to gurantee having views initialized you can use this code to get the UIViewControllers created in your storyboard
UIStoryboard *storyboard;
storyboard = [UIStoryboard storyboardWithName:"Story board name" bundle:nil];
UIViewController * leftSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
"Left side view identifier"];
UIViewController * centerSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
"center view identifier"];
UIViewController * rightSideNavController =
[storyboard instantiateViewControllerWithIdentifier:
"right side view identifier"];
then using the UIViewControllers you got from the previous point initialize the MMDrawerController
self.drawerController =
[[MMDrawerController alloc]
initWithCenterViewController:centerSideNavController
leftDrawerViewController:leftSideNavController
rightDrawerViewController:rightSideNavController];

TabBarController and NavigationController

I am making an application but I'm still a beginner and I'm trying to get used to the RootViewController and how it should be set.
At the beginning my application launches, I want there to be a View which is not in my tabBarController (which is set to be my rootViewController).
What I am trying to ask is, Can I have another view which is outside my UITabBarController launch first without it being in the tabBarController's items list?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
FacebookFeedViewController *facebookClass = [[FacebookFeedViewController alloc] initWithNibName:#"FacebookFeedViewController" bundle:nil];
TwitterFeedViewController *twitterClass = [[TwitterFeedViewController alloc] initWithNibName:#"TwitterFeedViewController" bundle:nil];
LinkedInFeedViewController *linkClass = [[LinkedInFeedViewController alloc] initWithNibName:#"LinkedInFeedViewController" bundle:nil];
FTLFullFeedViewController *masterClass = [[FTLFullFeedViewController alloc] initWithNibName:#"FTLFullFeedViewController" bundle:nil];
/// tab button title
facebookClass.title = #"Facebook";
twitterClass.title = #"Twitter";
linkClass.title=#"LinkedIn";
masterClass.title=#"FTL";
// tab button Images
facebookClass.tabBarItem.image = [UIImage imageNamed:#"facebook_32"];
twitterClass.tabBarItem.image = [UIImage imageNamed:#"twitter_32"];
WelcomeViewController *welcomeClass= [[WelcomeViewController alloc] initWithNibName:#"WelcomeViewController" bundle:nil];
navController = [[ UINavigationController alloc] initWithRootViewController:welcomeClass];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:facebookClass];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:twitterClass];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:linkClass];
UINavigationController *navController5 = [[UINavigationController alloc] initWithRootViewController:masterClass];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController5,navController2,navController3,navController4,nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I know you already selected an answer but all that's doing is pushing a UITabBar view on top of an existing view, not creating a new UITabBarController view. Based on our brief conversation (latest XCode, no StoryBoards, using XIBs) you're going to want to create a xib as a UITabBarController then push it into view...
View *view = [[View alloc] initWithNibName:#"myUITabBarXIB" bundle:nil];
view.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: view animated:YES];
This will present your XIB file but not on top of the existing view controller when the desired action takes place.
yes! ofcourse you do.
[self.view addsubview:yourTabbar.view];
Hope this will help you.

MMDrawerController with splitview

i have an app for both iphone and ipad.
a classic master/detail app for iphone and splitview for ipad.
I want to add a slide out menu using MMDrawerController Github
I manage to add it for iphone but i d'ont understand how to add it for ipad and to keep the splitview / NavigationController behavior.
Original code :
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:#"MyMasterViewController_iPhone" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
} else {
MyMasterViewController *masterViewController = [[MyMasterViewController alloc] initWithNibName:#"MyMasterViewController_iPad" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
MyDetailViewController *detailViewController = [[MyDetailViewController alloc] initWithNibName:#"MyDetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
}
[self.window makeKeyAndVisible];
Trying to use MMDrawerControler :
UIViewController * leftSideDrawerViewController = [[MMExampleLeftSideDrawerViewController alloc] init];
NSString *strViewMaster = #"MyMasterViewController_iPhone";
UIViewController * centerViewController = [[MyMasterViewController alloc] initWithNibName:strViewMaster bundle:nil];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
strViewMaster = #"MyDetailViewController_iPad";
centerViewController = [[MyDetailViewController alloc] initWithNibName:strViewMaster bundle:nil];
}
// unused
//UIViewController * rightSideDrawerViewController = [[MMExampleRightSideDrawerViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
MMDrawerController * drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController];
[drawerController setMaximumRightDrawerWidth:200.0];
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModePanningNavigationBar];
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];
//centerViewController.mm_drawerController = drawerController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:drawerController];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
So, on the ipad, the slide out menu is working, the detailview is loaded but i don't know how to define the masterViewcontroller / navigationcontroller so it does not work..
(sorry, i m a real nood with objective c and ios concept like you can see)
thank you
#picolo
Unfortunately, Apple enforces a UISplitViewController to be the rootViewController of a window, which means you can't place it inside a container view controller. You'll have to write your own similar split view controller implementation in order to drop it in another container view controller.
Cheers
MMDrawer Doesn't works with SplitViewController. Try using MFSlideMenu. It works with almost all types of controllers.
here is the link. --> MFSlideMenu
The MMDrawerController will not work with a SplitViewController. (as said int the github project description).

Resources