I have a login screen, and after auth, I have a tab bar controller with navigation controllers for each views, which I want to present.
Here is the code I use
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:#"tabBar"];
self.navigationController.navigationBarHidden=NO;
[self.navigationController pushViewController:obj animated:YES];
Problem is The tab bar is not showing. Also, how can I specify to show the second view in the tabbar controller if I needed to?
I am using storyboard.
thanks for any help.
Instead of pushViewController, do a [self presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion]
This will show the new view controller as full screen.
You can also create a named segue from the login screen to the tab controller with a modal transition style. You could then call [self perfromSegueWithIdentifier:#"YOUR SEGUE NAME" sender:nil];
To load the 2nd tab in the tab bar, you can do
[self.tabBarController setSelectedIndex:1]
to select the 2nd tab.
Related
In Periscope Live Broadcast app, when you click on WORLD tab bar and then tap on "List" and you tap to watch a live stream, the Live stream view controller will pop up from the bottom covering the entire tab bar view controller with the tab bar completely hidden.
(I'm currently using Tab Bar Controller and Navigation Controller and I can't get it done)
How is this done?
You can call your "modal" view controller programmatically:
NSString * storyboardName = #"MainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER_OF_YOUR_VIEWCONTROLLER"];
[self presentViewController:vc animated:YES completion:nil];
IDENTIFIER_OF_YOUR_VIEWCONTROLLER is the name you set in your storyboard. You can assign in the identity inspector of your storyboard.
This view will cover your screen as a modal
I have two storyboards:
Login / register purposes (without navigation view controller)
Main storyboard (with navigation view controller)
When I hit Logout button (navigation bar item) on Main storyboard I am redirected to Login storyboard, but still see the navigation bar.
How can I do this segue an also leave navigation view controller, so that navigation bar will not be visible ?
Here what you can do,
When you want to show a Login controller without navigation bar, use
UIStoryboard * board = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LoginCntrl * cntrl = [board instantiateViewControllerWithIdentifier:#"LoginCntrl"];
[self presentViewController:LoginCntrl animated:YES completion:^{
}];
Here 'LoginCntrl' in instantiateViewControllerWithIdentifier method is, the identifier of the LoginCntrl specified in storyboard.
Because presentViewController is not part of the navigation controller, this won't show you navigation bar at the top.
On logout event, change the rootViewController of window,
1) Create object of appDelegate
2) Create object of LoginVC
appDelegateObject.window?.rootViewController = objectOfLoginViewController;
I added a Navigation Controller to my storyboard and it appears like so:
Now in the table view controller, I gave the TableViewController a storyboard id and class to a TableViewController Controller
When I run my app, I don't see the Navigation Bar at the top. This has been extremely frustrating and can't find a solution anywhere. PLEASE HELP
To get to the scene, someone clicks a button and this code runs and it goes to my Table View Controller:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
LHFileBrowser *LHFileBrowser = [storyBoard instantiateViewControllerWithIdentifier:#"FileBrowser"];
[self.navigationController pushViewController:LHFileBrowser animated:YES];
[self presentViewController:LHFileBrowser animated:YES completion:nil];
The error is in your code.
If you want to (modally) present a view controller when the user presses a button, you need to present the navigation controller (which will contain the table view controller), not the table view controller itself.
Right now, you're presenting the view controller, which won't show it being embedded in a navigation controller.
Also, you're mixing up two different approaches, by trying to push a view controller onto a navigation controller stack, and also presenting the view controller.
Code Sample:
Here's what you apparently mean to do:
UIStoryboard *storyboard = self.storyboard;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"MyNavigationControllerID"];
LHFileBrowser *rootViewController = [navigationController topViewController];
// Configure your LHFileBrowser view controller here.
rootViewController.someProperty = ...;
// Modally present the embedded view controller
[self presentViewController:navigationController animated:YES completion:nil];
If you want to change the presentation or transition style, you can set those details in your storyboard.
You didn't explain why you had to programmatically add buttons, but Storyboard segues would have instantiated and presented an embedded view controller for you, without you having to have done it in code.
The more you can do in Storyboard, the less code you have to maintain, support, and update, and the more likely your app will still work properly when a new SDK is released.
Update:
The better way to do this is to let Storyboard do it for you, by adding a segue from the button to the navigation controller that you want to present.
I would like to have my application have custom buttons in the CameraViewController; one pushes to Rustles ViewController (Top VC in photo below) and the other transitions to ViewController (Bottom VC).
Right now my application can properly segue to the viewControllers by using the following method:
-(void)segueToRustlesTableViewController{
if (debug==1) {NSLog(#"Running %# '%#'", self.class, NSStringFromSelector(_cmd));} // simple debug statement, can ignore
// Instantiate nav controller which segues to table view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil]; // must assume only IPhone
RustlesTableViewController *rustlesTVC = (RustlesTableViewController *)[storyboard instantiateViewControllerWithIdentifier:#"RustlesView"];
[self performSegueWithIdentifier:#"tableSegue" sender:self];
[self.PickerController presentViewController:rustlesTVC animated:NO completion:nil];
}
However when I get to the UIViewControllers I can't transition back to the old UIViewControllers, presumably because I have no Navigation Controllers embedded in each UIViewControllers.
My code right now wouldn't work for a NavigationController but I don't really know how to transition to the NavigationController and then the UIViewControllers after the Navigation Controller.
How do I transition from CameraViewController to aNavigationController and then to the RustlesViewController?
If you aren't making use of a navigation controller, I would make a custom button in the spawned view controller (Rustles, View) and call
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
I believe this should work.
My app starts with a navigation controller which opens a UIViewController. This screen works as a login page.
On login, I open a UITabBarController like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:#"MainTab"];
self.navigationController.navigationBarHidden=YES;
[self.navigationController pushViewController:obj animated:YES];
Inside my tab bar controller, I want when clicking a button to switch tab programmatically. I tried the following 3, neither of them worked. Code is place inside a method, which is invoked when the button is clicked.
For the first 2, the tab didn't change - still my initial tab is highlighted and the correct view controller is not shown. For the last one, app crashes.
1st :
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
2nd :
[self.parentViewController.tabBarController setSelectedIndex:1];
3rd:
UITabBarController *MyTabController = (UITabBarController *)((AppDelegate*) [[UIApplication sharedApplication] delegate]).window.rootViewController;
[MyTabController setSelectedIndex:1];
What am I missing?
for a tabBar inside a navigation controller...What am I missing?
One thing you're missing is the order of containment that's allowed for view controllers. Specifically, you can put a navigation controller inside a tab controller, but not the other way around.