MMDrawerController with splitview - ios

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

Related

How to achieve SplitView Functionality in Portrait mode in iOS?

I'm trying to implement SplitView functionality in my iOS application, it's working fine only in landscape mode in iPad devices.
If I launch or rotate the application from landscape to portrait mode splitView functionality is collapsing.
How to achieve SplitView functionality in iPhone(portrait and landscape) and iPad(Portrait mode) devices?
Please find my codeenter image description here below code.
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController *masterViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc]initWithNibName:#"DetailViewController"
bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[CustomSplitViewController alloc]initWithNibName:#"CustomSplitViewController" bundle:nil];
self.splitViewController.viewControllers = #[masterNavigationController, detailNavigationController];
TabBarDetailController *secondVC = [[TabBarDetailController alloc]initWithNibName:#"TabBarDetailController" bundle:nil];
secondVC.tabBarItem.title = #"Second";
ThirdViewController *thirdVC = [[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
thirdVC.tabBarItem.title = #"Third";
FourthViewController *fourthVC = [[FourthViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
fourthVC.tabBarItem.title = #"Fourth";
MoreViewController *moreVC = [[MoreViewController alloc]initWithNibName:#"MoreViewController" bundle:nil];
moreVC.tabBarItem.title = #"More";
//make an array containing view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:self.splitViewController,secondVC,thirdVC,fourthVC,moreVC,nil];
[tabBarController setViewControllers:viewControllers];
self.splitViewController.tabBarItem.title = #"HOME";
[self.window addSubview:tabBarController.view];
self.window.rootViewController=tabBarController;
[[self window] makeKeyAndVisible];
return YES;
}
Thanks in advance.

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

ios splitviewcontroller landscape fail

I have spliteview project and forced it in landscape mode.
It works fine before I upgrade my iOS SDK to iOS6.
But after upgrade, when I use iOS 5.1 Simulator to run, it always show in portrait mode and Master view is gone.
and here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
CustomverDetailViewController *custView = [[[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil] autorelease];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, custView];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
Any ideas?
I try to give different code for different version, in iOS6 it seems ok, but in iOS5.1 still will changing orientation while I enter this view, I guess when I alloc an new UIWindow , it orginial orientation is portrait.
here I changed my code:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
left = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:left] autorelease];
right = [[CustomverDetailViewController alloc] initWithNibName:#"CustomverDetailViewController" bundle:nil];
self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = #[masterNavigationController, right];
if (([[[UIDevice currentDevice] systemVersion] floatValue ] < 6.0 )) {
self.splitViewController.delegate = left;
[self.splitViewController.view setFrame:CGRectMake(0, 0, 1024.0f, 768.0f)];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}else{
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
[right release];
Try to add new delegate method added in iOS 6
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)shouldAutorotate {
return NO;
}

Resources