MMDrawerController instantiation - ios

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

Related

MMDrawerController with Login View as first view

I am using MMDrawerController Library.
My application is in Objective C. It has a login screen as its first screen.
Code for AppDelegate.m
LoginViewController* loginView= [[LoginViewController alloc]initWithNibName:#"LoginViewController"] bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:loginView];
self.loginViewController = navigationController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:navigationController];
[window makeKeyAndVisible];
Now When LOGIN is successful I goto HomeViewController. Here I have to change the rootViewController to MMDrawerController for the Library to work. For this I am writing the following code in ViewDidLoad() of HomeViewController.m
-(Void)methodCalledInViewDidLoad
{
UIViewController * leftSideDrawerViewController = [[MMExampleLeftSideDrawerViewController alloc] init];
UIViewController * centerViewController = [[HomeViewController alloc] init];
UIViewController * rightSideDrawerViewController = [[RightViewController alloc] init];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[navigationController setRestorationIdentifier:#"HomeViewController"];
self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:navigationController leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:nil];
[self.drawerController setRestorationIdentifier:#"HomeViewController"];
[self.drawerController setMaximumLeftDrawerWidth: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);
}
}];
appDelegate.self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[appDelegate.self.window setRootViewController:self.drawerController];
}
This is not working and showing errors. I have followed all tutorials available. The rootViewController is not changing to drawerController in HomeViewController
AppDelegate *appDel=(AppDelegate)[[UIApplication sharedApplication]delegate];
[appDel.window setRootViewController:self.drawerController];
Still not working go to MFSlidebar. https://github.com/mikefrederick/MFSideMenu

IIViewDeckController is not working when push by navigation controller

Please help me in my project. I am using IIViewDeckController but its not working when pushed by view controller
Heres the hierarchy:
ViewController (Push)----> IIViewDeckController (with Left and centerview).
Here is my code when initialising the IIViewDeckController:
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
self.profileView = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
UINavigationController* navC = [[UINavigationController alloc] initWithRootViewController:self.profileView];
IIViewDeckController *deckView = [[IIViewDeckController alloc] initWithCenterViewController:navC leftViewController:self.navigationView rightViewController:nil];
deckView.leftSize = 50;
[deckView disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return deckView;
}
then this is my code when I'm pushing IIViewDeckController using another ViewController
- (IBAction)signInAction:(id)sender {
IIViewDeckController *deckView = [[UIManager sharedItems] generateControllerStack];
[self.navigationController pushViewController:deckView animated:YES];
}
Thanks you very much guys :)
when I clicked sign in which is I will push my iiviewdeckcontroller with left and centre view this appears
Did you created it like this?
I am using it as root view controller. and it is working fine
UINavigationController* navController=(UINavigationController*)[[UIStoryboard storyboardWithName:#"Main" bundle: nil] instantiateViewControllerWithIdentifier:#"HomeViewController"];
SlideMenuViewController* slide=[[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"SlideMenuViewController"]; /
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:navController
leftViewController:slide
rightViewController:nil
topViewController:nil
bottomViewController:nil];
float leftSize=self.window.frame.size.width - (88*self.window.frame.size.width)/320;
deckController.panningMode = IIViewDeckFullViewPanning;
deckController.leftSize =leftSize;
You can do like that.
//Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController"
bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
import IIViewDeckController.h in ViewController.h then
- (IBAction)GoToNext:(id)sender
{
IIViewDeckController *objIIVC = [self.storyboard instantiateViewControllerWithIdentifier:#"Your VC's Identifier"];
[self.navigationController pushViewController:objIIVC animated:YES];
}
Here is my code
- (IIViewDeckController*)generateControllerStack{
self.navigationView = [[NavigationViewController alloc] initWithNibName:#"NavigationViewController" bundle:nil];
UIViewController *centerController = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
centerController = [[UINavigationController alloc] initWithRootViewController:centerController];
self.viewDeck = [[IIViewDeckController alloc] initWithCenterViewController:centerController leftViewController:self.navigationView rightViewController:nil topViewController:nil bottomViewController:nil];
self.viewDeck.leftSize = 50;
[self.viewDeck disablePanOverViewsOfClass:NSClassFromString(#"_UITableViewHeaderFooterContentView")];
return self.viewDeck;
}

MMDrawerController Library to work with storyboard

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.

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).

How to insert UINavigationController inside UITabBarController

How to insert UINavigationController inside UITabBarController.
Currently I have main UITabBarController with declatarion inside application delegate like this (so tab is main)
self.window.rootViewController = self.tabBarController;
And inside one of tabs I want to insert UINavigationController, and can't get it.
The code is contructed like this:
MainWindow.xib with UITabBarController object with tab typed as UINavigationController (point to NavigationHistory.xib) - screenshot: invalid link
NavigationHistory.xib contains only UINavigationController where view point to History.xib
History.xib have only UITableView element - screenshot: invalid link
And now UIViewController doesn't display my View1 view, and I have no clue why it may be. Maybe you have any clue? or point me to the place where such configuration is done.
I'll answer myself. It's good explained at
https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html
Write a code in appdelegate.m file.....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSMutableArray *Mutablearray = [[NSMutableArray alloc] init];
UIViewController *1st_View = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPhone" bundle:nil];
UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:1st_View];
[Mutablarray addObject:Navigation];
UIViewController *2nd_View = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
UINavigationController *Navigation = [[UINavigationController alloc] initWithRootViewController:2nd_View];
[Mutablearray addObject:Navigation];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = Mutablearray;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Add your controller object to UINavigationController, and add that navigationcontroller object to UITabBarController
UINavigationController is a subclass of UIViewController, a UITabBarController expects an array of UIViewControllers (and therefore UINavigationController ); this tells me me that I can give a UITabBarController an array of UINavigationControllers (or sublasses thereof) giving the desired interaction.
Ref : https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITabBarController_Class/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tab = [[UITabBarController alloc] init];
SimpleTableViewController *tableView = [[SimpleTableViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView];
UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:0];
nav1.tabBarItem = item;
AboutViewController *about = [[AboutViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:about];
UITabBarItem *item2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
nav2.tabBarItem = item2;
tab.viewControllers = #[nav1,nav2];
self.window.rootViewController = tab;
[self.window makeKeyAndVisible];
return YES;
}

Resources