Hi, this is my storyboard , i wanna go from First view controller to LoggedinViewController.
Im normally using
[self performSegueWithIdentifier:#"s1" sender:self];
but if i add tab bar controller this line is not working , how can i fix this ?
You can use the following if you have embedded into navigation controller.
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TABid"];
self.tabBarController.selectedIndex = 0;
[self.navigationController pushViewController:self.tabBarController animated:YES];
Or try this
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TABid"];
self.tabBarController.selectedIndex = 0;
[self performSegueWithIdentifier:#"s1" sender:self];
Give your tabbarcontroller an identifier from the storyboard, the do something like this
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Your_Story_Board_Name" bundle:nil];
TabViewController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TAB_Identifier"];
[self presentViewController:tabBarController animated:YES completion:nil];
Hope this helps
first give "tabbarid" to that tab inside storyboard
UITabBarController *tabBarController1 = [self.storyboard instantiateViewControllerWithIdentifier:#"tabbarid"];
tabBarController1.selectedIndex = 1;
[self presentViewController:tabBarController1 animated:YES completion:nil];
Related
This question already has answers here:
presentViewController and displaying navigation bar
(12 answers)
Closed 5 years ago.
Hi there I used this code to move in to new contorller just with code and without segue .
UIStoryboard * mainstoryb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * vc = [mainstoryb instantiateViewControllerWithIdentifier:#"online_shop"];
[self presentViewController:vc animated:YES completion:nil];
how do I show Navigation bar or title bar on next view ?
You need to present NavigationController as below :
UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:ContactUSVCID];
UINavigationController *objNav = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:objNav animated:YES completion:nil];
if you want navigation bar, then you have to push not present
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
SecondViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"ViewControllerB"];
/********if dont have navigation bar***********/
UINavigationController *initialNavigationController = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:#"HomeNavCtrl_id"];
[self presentViewController:initialNavigationController animated:YES completion:nil];
/**********else*************/
[[self navigationController] pushViewController:vc animated:YES];
Embed your ViewController in navigation controller and storyboard id to navigation controller then use this code
UINavigationController *initialNavigationController = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:#"HomeNavCtrl_id"];
[self presentViewController:initialNavigationController animated:YES completion:nil];
If you present a view controller it will always be presented full screen.
Try this
UIStoryboard * mainstoryb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * vc = [mainstoryb instantiateViewControllerWithIdentifier:#"online_shop"];
[self presentViewController:navigationController animated:YES completion:nil];
I have 5 view controller and want to come back from the last view to 1st view controller
Call a function in which you have to change the app rootviewcontroller. set it as a navigationController
yourViewcontoller *viewController = [[yourViewContoller alloc] init];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController = navController;
If you're using storyboards, give the UINavigationController a Storyboard ID. You can then initiate it and present through the code:
UINavigationController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"<Storyboard ID>"];
[self presentViewController:vc animated:YES completion:nil];
Use this method on Animation splash screen
[self performSelector:#selector(setHidden:) withObject:nil afterDelay:2.0];
-(void) setHidden:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboare" bundle:nil];
YourVC* vController = (YourVC*)[Storyboard instantiateViewControllerWithIdentifier:#"storyboardId"];
UINavigationController *navcotoller=[[UINavigationController alloc]initWithRootViewController:vController];
self.window.rootViewController =navcotoller;
}
If you are using UINavigationController you could and should simply call
[self.navigationController popToRootViewControllerAnimated:YES];
I've got the iPhone working fine with creating a segue programmatically.
e.g.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone"
bundle:nil];
FooBarViewController *foobarViewController = (FooBarViewController *)[storyboard instantiateViewControllerWithIdentifier:#"foobarViewControllerID”];
[self.navigationController pushViewController:foobarViewController animated:YES];
Now I'm trying to do something similar on the iPad storyboard.
The goal being to programmatically change the detail view to a view on the storyboard.
I thought maybe:
[self.splitViewController.navigationController presentViewController:foorbarViewController animated:NO completion:nil];
However this doesn't work. Any suggestions?
I believe I've solved my own question with the following function:
- (void) presentDetailView : (UIViewController *) viewcontroller {
UINavigationController *detailNavCtrl = [[UINavigationController alloc] initWithRootViewController:viewcontroller];
detailNavCtrl.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
detailNavCtrl.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[[[self.splitViewController viewControllers] lastObject] presentViewController:detailNavCtrl animated:NO completion:nil];
}
I'm developing an application, and at some point I need a Modal ViewController to "become" the Root ViewController.
How can I dismiss the current rootController, and set my Modal as my new rootController?
First you have to set your root view controller nil.
[self.window setRootViewController:nil];
UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle: nil];
Nearbylocations *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"near"];
self.window.rootViewController=introViewController;
You can try below code..
[self dismissViewControllerAnimated:NO completion:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:modalviewref];
[self.navigationController presentViewController:navBar animated:YES completion:nil];
Hope it helps you..!
I have this code
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:#"PlaceView"];
[self presentViewController:newView animated:YES completion:nil];
And I can change view, but I would push this view for when I return at this page, the state persists.
I try to put this code:
[self.navigationController pushViewController:newView animated:YES];
but doesn't do anything.
Thanks
Objective-C:
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:#"storyBoardIdentifier"];
[self.navigationController pushViewController:newView animated:YES];
Please do notice below points,
your storyboard identifier is correct.
The root view have navigation Controller.
Swift:
let newView = self.storyboard?.instantiateViewController(withIdentifier: "storyBoardIdentifier") as! PlaceViewController
self.navigationController?.pushViewController(newView, animated: true)
For Storyboards, you should use performSegueWithIdentifier like so:
[self performSegueWithIdentifier:#"identifier goes here" sender:self];
Use:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:#"PlaceView"];
[self presentViewController:newView animated:YES completion:nil];
Or:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"STORYBOARD_NAME" bundle:nil];
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:#"PlaceView"];
[self.navigationController pushViewController:newView animated:YES];
Swift 3.x
let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController
navigationController?.pushViewController(viewController, animated: true)
By default, Xcode creates a standard view controller. we first change the view controller to navigation controller. Select the Simply select “Editor” in the menu and select “Embed in”, followed by “Navigation Controller”
Step 1. Select Main story board
Step 2.Click on "Editor" on top of your Xcode application.
Step 3. Click on "Embed In"
Xcode automatically embeds the View Controller with Navigation Controller.