I try navigate to FrontViewController of SWRevealViewController from AppDelegate
In AppDelegate.m
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
Home_tableView *home =[storyboard instantiateViewControllerWithIdentifier:#"home_view"];
[(UINavigationController *)self.window.rootViewController pushViewController:home animated:NO];
when it load my Home_tableView.m in viewDidLoad method,I got self.revealViewController is nil & its crash
SWRevealViewController *revealViewController = self.revealViewController;
_nav_bar.target = self.revealViewController;
_nav_bar.action = #selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
My storyboard like this
you have to try like this may be help you.
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"revealidentifier"];
Now use vc as your revealViewController.
NOTE: You have to enable navigationcontroll "FirstViewController"
I think you are using SWRevealViewController which is on Github
and you can follow this tutorial to integrate it into your app.
this is really amazing tutorial and it will help you
http://www.appcoda.com/ios-programming-sidebar-navigation-menu/
Thank to #Dipen Chudasama I get the answer
in my AppDelegate.m file , I put this code to navigate to my slide menu (SWRevealViewController)
UIStoryboard *storyboard =[UIStoryboard storyboardWithName:#"Main" bundle:nil];
SWRevealViewController *home = [storyboard instantiateViewControllerWithIdentifier:#"reveal"];
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:home animated:YES completion:NULL];
Thank you for every one try to help me
Related
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];
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 have three UIViewControllers ViewController, HomeViewController and RegisterViewController using storyboard. Their Storyboard ID is Login, Home and Registration respectfully. There is a button on RegisterViewController view named 'Register'. After successful registration i want to go to home page i.e., HomeViewController. How to do it. Please help I'm new to iOS.
thanks
- (IBAction)yourRegisterButtonAction:(id)sender
{
[self performSegueWithIdentifier:#"YOUR_SEUGE_NAME" sender:nil];
}
Try This
- (IBAction)buttonRegister:(id)sender {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
// replace Main with your storyboard name
HomeViewController *homeVC = [storyboard instantiateViewControllerWithIdentifier:#"Home"];
[self.view addSubview:homeVC.view];
}
Implement a navigation controller and do this.
-(IBAction)registerButtonTapped:(id)sender{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
HomeViewController *viewController =(HomeViewController*) [storyboard instantiateViewControllerWithIdentifier:#"Home"];
[self.navigationController pushViewController:viewController animated:YES];
}
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.
I have multiple storyboards within my app. I want to pass an object when a new storyboard is opened.
I'am doing this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"SetupStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController* initialHelpView = [storyboard instantiateInitialViewController];
SetupViewController *setup = (SetupViewController*) [initialHelpView topViewController];
setup.data = self.data;
initialHelpView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:initialHelpView animated:YES completion:nil];
But when the storyboard is presented the setup.data is nil in viewDidLoad, viewWillAppear etc of the SetupViewController...
Why is that?
I don't see anything wrong with this code. Problem may be elsewhere.