I'm using a Tabbarcontroller and I want a side menu in the first tab of the tab bar. For the side menu I'm using MMDrawerController.
I'm using storyboard
How should I proceed ?
Following code is working for me, I have written this code in viewDidload of LoginScreen, In Storyboard i have created LoginScreen as rootviewController with embeded navigationController (means navigationController is storyboard entry point and LoginScreen is rootViewController).
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vcSideMenu = [storyBoard instantiateViewControllerWithIdentifier:#"SideMenuScreen"];
UITabBarController *tabBar = [storyBoard instantiateViewControllerWithIdentifier:#"tabBar"];
MMDrawerController *controller = [[MMDrawerController alloc] initWithCenterViewController:tabBar leftDrawerViewController:vcSideMenu rightDrawerViewController:nil];
CGFloat menuWidth = [UIScreen mainScreen].bounds.size.width * 0.8;
[controller setMaximumLeftDrawerWidth:menuWidth];
[controller setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
[controller setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.navigationController pushViewController:controller animated:NO];
Related
I created a SingleView application then use "Embed In Navigation Controller" to get a navigation control.
when push a controller, the viewcontroller's backgroundColor is black.
i know use this code :
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];//UIStoryboard(name: "Main", bundle:nil)
UIViewController *roomController = [storyBoard instantiateViewControllerWithIdentifier:#"controlerID"];
but what's the reason ?
and if i don't want to use the storyboard completely ,only use this code
UIViewController *roomController = [[UIViewController alloc]init];
what can i do? is only set the viewcontroller's backgroundColor?
You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *roomController = [storyboard instantiateViewControllerWithIdentifier:#"controlerID"];
[self.navigationController pushViewController: roomController animated:YES];
// if You make controller with out storyboard Than change You view color
UIViewController *roomController = [[UIViewController alloc]init];
[self.navigationController pushViewController: roomController animated:YES];
- (void)viewDidLoad
{
self.view.backgroundColor =[UIColor whiteColor];
}
The first ViewController is managed by a NavigationController, and it has a UIWebView. The WebView modules has click events to push a ViewController in the NavigationController.
But now, the ViewController which is init by code is normal, and which is init by storyboard is abnormal, the navigation bar was disappeared. It only occurs in iOS8 and earlier Version.
PS: The Init Code is like this:
Code:
ViewController *vc = [[ViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
Storyboard:
ViewController *vc = [ViewController defaultViewControllerWithStoryboard:#"StoryboardName"];
[self.navigationController pushViewController:vc animated:YES];
Thank You.
MainViewController* presentController = [self.storyboard instantiateViewControllerWithIdentifier:#"StoryBoardidentifier"];
[self.navigationController pushViewController:presentController animated:YES];
if its not working try this Normally yourStoryBoardName is Main:
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:#"YourStoryBoardName" bundle:nil];
MainViewController* presentController = [storyBoard instantiateViewControllerWithIdentifier:#"StoryBoardIdentifier"];
[self.navigationController pushViewController:presentController animated:YES];
i am using UINavigationController but when i push a view controller just simply by making object of the class the class load but not the components in it.
this is my AppDelegate.m
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ViewController *vc = [sb instantiateInitialViewController];
UINavigationController *nav = [[UINavigationController alloc] init];
self.window.rootViewController = nav;
nav.viewControllers = #[vc];
and my first UIViewController if action button code is
NextView *next = [[NextView alloc] init];
[self.navigationController pushViewController:next animated:YES ];
it gets to next UIViewController but no internal components are loaded such as - button,textfield,etc.
and if i try this code it give me runtime error
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NextView *next = [sb instantiateViewControllerWithIdentifier:#"two"];
[self.navigationController pushViewController:next animated:YES ];
make sure that NextView inherit UIViewController and you have given identifier as two to that view controller and you have set class NextView from identity inspector to that viewcontroller.
Hope this will help :)
You could not get outlets (buttons etc.) to be loaded with alloc init in the subclass of UIViewController. You should init it with the xib file, using -initWithNibName:bundle: method. Or you can instantiate it with storyboard.
// You can get current storyboard from the View Controller
UIStoryboard *sb = vc.storyboard;
NextView *next = [sb instantiateViewControllerWithIdentifier:#"two"];
[self.navigationController pushViewController:next animated:YES];
I have a custom UIPageViewController which contain 5 UIViewControllers, now I would like to navigate from one of those 5 UIViewController, But I can't because in those UIViewControllers have no UINavigationController. Can anyone suggest me , how I can navigate from one those 5 UIViewControllers to other UIViewController?
The code in your - [AppDelegate application:didFinishLaunchingWithOptions:]
might look like this (after checking your skipping condition of course):
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc1 = [storyboard instantiateViewControllerWithIdentifier:#"MyAuth"]; //if you assigned this ID is storyboard
UIViewController *vc2 = [storyboard instantiateViewControllerWithIdentifier:#"Login"]; //if you assigned this ID is storyboard
UIViewController *vc3 = [storyboard instantiateViewControllerWithIdentifier:#"Details"];
NSArray *controllers = #[vc1, vc2, vc3];
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
[navController setViewControllers:controllers];
If you paste just this to - [AppDelegate application:didFinishLaunchingWithOptions:], you'll see that it works immediately.
I use swrevealviewcontroller to add slide menu to my app ,
Let consider we have menu like this one in pic
I need navigate from My appDelegate to any item in menu (ex:Map View Controller )
my tries :
in my appDelegate.m
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
InforView *school_view = [storyboard instantiateViewControllerWithIdentifier:#"info_view"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:school_view animated:YES completion:NULL];
When its move to InforView Controller it crash in viewdidload
- (void)viewDidLoad
{
[super viewDidLoad];
_nav_bar.target = self.revealViewController;
_nav_bar.action = #selector(revealToggle:);
// its crash here
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
my storyboard
navigation controller --> home view --> reveal View controller
reveal View controller has two views --> slide menu
navigation controller -- > Front view
my slide menu has some items as appear in pic
I need navigate from my appDelegate to one of this items
Finally I find the answer
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// this any item in list you want navigate to
Home_tableView *home = (Home_tableView *) [storyboard instantiateViewControllerWithIdentifier:#"home_view"];
SlideMenu *slidemenu = (SlideMenu *)[storyboard instantiateViewControllerWithIdentifier:#"Menu_view"];
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;
In the SidebarDemo project, you can use the following code to show MapViewController on initial loading.
SWRevealViewController *revealViewController = (SWRevealViewController*)self.window.rootViewController;
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MapViewController *mapVC = [storyboard instantiateViewControllerWithIdentifier:#"MapID"];
[self.window makeKeyAndVisible];
UINavigationController* navController = (UINavigationController*)revealViewController.frontViewController;
[navController setViewControllers: #[mapVC] animated: NO ];
[revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
After makeKeyAndVisible, the frontViewController and realViewController of the revealViewController are loaded. And you can set rootViewController of frontViewController, which is a navigationController.