I don't understand this. On method didFinishLaunchingWithOptions, When I set self.window.rootViewController = <instance of LoginViewController>, it shows full of Login screen as expectation. But when I add LoginViewController into NavigationController and then set self.window.rootViewController = <instance of NavigationController>, a part on the top of the Login screen is hidden?
The reason is that, upper area of the view is being covered by navigation bar so you can hide it with this code
[[self navigationController] setNavigationBarHidden:YES animated:YES];
That's because, by default, the navigation controller has the navigation bar visible. To ensure that the navigation bar is hidden in your login screen, you should call in viewDidLoad() method of login screen view controller self.navigationController?.setNavigationBarHidden(true, animated: false)
Related
I have a tabBarController and when I push a view controller I am hiding the bottom bar to not show the tabBar in the second view controller. The problem is that I see a white space for a moment.
This is de code I am using to push the view controller
VerResultadoViewController *controller = (VerResultadoViewController *)[self.storyboard instantiateViewControllerWithIdentifier:#"ver_resultado"];
controller.hidesBottomBarWhenPushed = YES ;
[self.navigationController pushViewController:controller animated:YES];
This is the white space:
Call the hideBottomBarWhenPushed in viewWillAppear or viewDidAppear (can't remember what the correct one is; you have to experiment) of the controller you are pushing.
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'm a bit lost trying to figure it out...
I have a tab bar based app with login screen at the start. Login screen should be done as Modal View Controller BEFORE tab bar controller appears.
The problem is that I can present it only in viewDidAppear: method of TabBarController. And user can see for half a second content of the UITabBarController. I've tried to move call to viewDidLoad: or viewWillAppear: but it logs an error in console: "whose view is not in the window hierarchy!". As far as I can understand you can only add ModalViewController when all child UIViewControllers of UITabBarController are loaded, ad that happens in viewDidAppear: delegate method.
Do you have any solution how to show login screen without showing TabBarController before?
I've tried 2 ways of displaying ModalViewController, both of them work in viewDidAppear: only
XIB file with login view and using presentViewController: code
self.loginController = [[LoginViewController alloc] init];
[self presentViewController:self.loginController animated:NO completion:nil];
Storyboard, modal segue and calling it from the code:
[self performSegueWithIdentifier:#"loginScreen" sender:self];
Instead of a modal, you might consider pushing the login screen onto a navigation stack. Inside viewWillAppear: you can just instantiate your login viewController and push it. You could also do it in viewDidLoad if you'd like.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController pushViewController:yourInstantiatedLoginViewController animated:NO];
}
I have a tab bar controller with 4 tabs and each tab is their own UINavigationController, which is how you're supposed to nest tab bar and navigation controller's together. The initial tab is a TableViewController and works/appears the way that it should. From the tableVC I can push standard view controller's onto the navigation controller with:
[self.navigationController pushViewController:VC animated:YES];
and it works properly.
If I attempt to push another TableViewController onto the navigation with the same method it works the same way, but the initial tab bar does not get pushed off screen like it should, it just stays in place.
Why would the tab bar stay on screen even though I am pushing a new VC onto the navigation?
I have tested with multiple instances of different TableVC's and it only happens with a table view controller.
Here is the code I'm using:
- (void)pushTableVC
{
TestTableVC *tableVC = [[TestTableVC alloc] init];
[self.navigationController pushViewController:tableVC animated:YES];
}
This will push the new table view onto the stack, but the tab bar from the parent VC stays in place and does not get pushed off screen like it should.
You should call the method setHidesBottomBarWhenPushed: on the view controller you are pushing to correctly hide the tab bar.
UIViewController *viewController = [[UIViewController alloc] init];
[viewController setHidesBottomBarWhenPushed:YES];
[[self navigationController] pushViewController:viewController animated:YES];
When you use a UITabBarController, the tab bar always stays on screen, even as you push additional view controllers onto an embedded UINavigationController. You will see this in any app that has a UITabBarController implemented, unless they implement custom behavior to change this.
The UINavigationController contains everything above the UITabBar, but does not contain the UITabBar itself, so it would not be able to push it offscreen.
I have this UINavigationController that when pushed automatically goes to landscape but can be changeable.
When I pop the view in portrait it goes back to the first/root view normally but when I pop the view in landscape, the back button remains and when I press it, it animates just like when popping a normal navigation controller and the button disappears.
I tried logging the view controllers whenever the main view appears and same with the second view, the logs that I got we're quite normal. On the first view only 1 view controller, and on the pushed view only 2 view controllers.
So, what could be the problem?
I'm not adding any custom buttons at all. It's the standard UINavigationController's back button.
Code:
Pushing the view controller
SomeViewController *rmVC = [[SomeViewController alloc] initWithNibName:#"SomeViewController" bundle:nil];
AppDelegate *ad = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[ad.someNavigationController pushViewController: rmVC animated:YES];
This was done in this way 'cause this was pushed in a presentModalViewController
At someViewController's viewDidLoad
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
Pics
http://s1058.photobucket.com/albums/t411/shlbypuerto/