MMDrawerController with Login View as first view - ios

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

Related

MMDrawerController configure left menu

My Left menu displace center view. It looks worse than if Left Menu cover center view.
explanation
How i can configure it?
//MMDrawerController
ViewController * centerViewController = [[ViewController alloc] init];
UINavigationController *centerNavigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
ViewController *leftViewController = [[ViewController alloc] init];
UINavigationController *leftNavigationController = [[UINavigationController alloc] initWithRootViewController:leftViewController];
_drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNavigationController leftDrawerViewController:leftNavigationController];
[leftNavigationController setNavigationBarHidden:YES];
[centerNavigationController setNavigationBarHidden:YES];
[_drawerController setMaximumLeftDrawerWidth:300.0];
[_drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIColor * tintColor = [UIColor colorWithRed:29.0/255.0
green:173.0/255.0
blue:234.0/255.0
alpha:1.0];
[self.window setTintColor:tintColor];
[self.window setRootViewController:_drawerController];
[self.window makeKeyAndVisible];

App Delegate call for Apple Push Notification doesn't present viewcontroller

I have embedded apple push notifications to my app. When a notification is popped, I get an alert view and when clicked on view, I navigate to a Details controller. But, after clicking on the view button, it does not do anything and it freezes the application. Here's my code to open details in alert view click:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
RearTableViewController *rearView = [[RearTableViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
[self.window makeKeyAndVisible];
Thanks in advance!
//Don't realloc self.window.
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
DetailsViewController *list = [[DetailsViewController alloc]initWithNibName:#"Details" bundle:nil];
//Alloc this VC with nib name like initWithNibNamed:bundle:
RearTableViewController *rearView = [[RearTableViewController alloc]initWithNibName:#"RearTableViewController" bundle:nil];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:list];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearView];
SWRevealViewController *mainRevealController = [[SWRevealViewController alloc]
initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
mainRevealController.delegate = self;
if(self.window.rootViewController){
[self.window.rootViewController presentViewController:mainRevealController animated:YES completion:nil];
}
else{
self.window.rootViewController = mainRevealController;
}
[self.window makeKeyAndVisible];
Hope it will work.
Remove the following code.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
No need to allocate the window once again. If you do so, you have to set the rootViewController again.

How to programmatically add a UITabBarController & UINavigationController in AppDelegate?

How to add a UINavigationController & UITabBarController programmatically in app delegate.
Don't forget in the AppDelegate.h file to add:
#property (strong, nonatomic) UITabBarController *tabBarController;
Below is the AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.tabBarController = [[UITabBarController alloc] init];
ViewController1 *VC1 = [[ViewController1 alloc] init];
VC1.title = #"Tab Title Here";
UINavigationController *VC1Navigation = [[UINavigationController alloc]
initWithRootViewController:VC1];
ViewController2 *VC2 = [[ViewController2 alloc] init];
VC2.title = #"Tab Title Here";
UINavigationController *VC2Navigation = [[UINavigationController alloc]
initWithRootViewController:VC2];
ViewController3 *VC3 = [[ViewController3 alloc] init];
homeView.title = #"Tab Title Here";
UINavigationController* VC3Navigation = [[UINavigationController alloc]
initWithRootViewController:VC3];
NSArray* controllers = [NSArray arrayWithObjects:VC1Navigation, VC2Navigation, VC3Navigation, nil];
self.tabBarController.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}

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

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