iOS - How to not show a navigation bar on a screen? - iphone

I'm looking for a way to have a navigation bar not show up on a screen at all.
I know there is a setNavigationBarHidden:animated: to use on the navigationbar, but this still shows the bar on the screen for a split second before removing and readjusting the screen dimensions.
I've tried moving the setNavigationBarHidden:animated: to the viewDidLoad:, viewWillAppear: etc. and set it hidden on the previous activities viewWillDisappear: but it will shows up on the next screen.
How do I make it such that the view loads with out a navigationbar on it before it is shown?
Thanks,
Dman

I'm hiding the navigation bar for the UINavigationController in the AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method and works fine for me. At some point, while navigating through the screens, I'm showing it then hide it again. Works like a charm.
UIViewController *controller = [[UIViewController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController: controller];
navCtrl.navigationBarHidden = YES;
self.window.rootViewController = navCtrl;
[controller release];
[navCtrl release];
Hope this helps.
P.S. Actually I never show the navigationBar of the navigation controller again. On the controllers that need the bar I'm adding a new one.

You could try and do
setNavigationBarHidden:animated:
in your view which is calling the view where you don't want it to be displayed just before you call your new view. If they have the same navigationcontroller, it should already be hidden if it appears
if not, you try to set it on the navigation oder viewcontroller before your present it...

Related

Navigation Controller - How to Add in Another View Controller in Xcode?

I'm relatively new to iOS programming but I'm learning bit by bit. I've got two nib files, one is my HomeViewController and the other is called 'ReceiptTableViewController'. The HomeVC should not have a top nav bar but the ReceiptTableVC should, with a title and 'back' where the user can swipe to go back to HomeVC.
How would I go about adding this? I've dragged the Navigation Controller to the side of my ReceiptTableVC in the nib file.
I've searched for various answers but some contradict each other as the authors use different versions of Xcode, and some start with storyboards, etc.
Any help is much appreciated!
I haven't used storyboard
You can use this method to decide whether your navigationBar show or not in your viewController.[self.navigationController setNavigationBarHidden: animated:];
In your AppDelegate:
UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:homeController];
naviController.navigationBarHidden = YES; //set home controller navigation bar hidden.
self.window.rootViewController = naviController;
Then in your ReceiptTableViewController's viewDidLoad method:
[self.navigationController setNavigationBarHidden:NO animated:NO]; // show the navigation bar.
This is how to declare a UINavigationController programmatically. You can have a try.

Tab Bar in Iphone Programming?

I make an application using Tab Bar.
I have 2 views controller: View1 and View2 and a RootViewController.
In RootViewController.m:
- (void)viewDidLoad
{
[self.navigationItem setTitle:#"Tab Bar"];
View1 *vc1 = [[View1 alloc]init];
View2 *vc2 = [[View2 alloc]init];
[vc1.tabBarItem setTitle:#"View1"];
[vc2.tabBarItem setTitle:#"View2"];
[self setViewControllers:[NSArray arrayWithObjects:vc1, vc2, nil]];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
When I build application, I have an error: Have a white place. When I go to View 2 and back to View 1 it is disappeared. I want to delete white place. Please see image in here: http://photo.ssc.vn/images/108Screen_Shot_2013_08_18.jpg
Thanks for your helping!
This is a common issue when adding view controllers to a tab bar.
The solution is to set wantsFullScreenLayout on the UINavigationController to NO, so it won't even attempt to leave that gap for the status bar.
Apple says :
Tab bar controllers support full-screen layout differently from the
way most other controllers support it. You can still set the
wantsFullScreenLayout property of your custom view controller to YES
if you want its view to underlap the status bar or a navigation bar
(if present). However, setting this property to YES does not cause the
view to underlap the tab bar view. The tab bar controller always
resizes your view to prevent it from underlapping the tab bar.
For more detailed explanation you can see this Question.

iPhone: a same bottom bar for several views

I would like to add a bottom bar in a view and then keep it there while I browse several views (each one with a nab bar). I hope it will follow Apple guidelines (I already know that only the nab bar is recommended) or at least the app is accepted.
For doing so, I have added a UIView to the application window. This UIView contains a UITabBarController which contains the navigation controllers (each one as a rootviewController) of each one of the items of the bar:
UIWindow *window=[[UIApplication sharedApplication] keyWindow];
MyUIViewController *mv=[[MyUIViewController alloc]init];
UINavigationController *navd = [[UINavigationController alloc] initWithRootViewController:mv];
navd.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"MyItem" image:[UIImage imageNamed:#"myImage.png"] tag:0];
NSMutableArray *controllers = [[NSMutableArray alloc] init];
[controllers addObject:navd];
UITabBarController *tbarController=[[UITabBarController alloc] init];
tbarController.viewControllers = controllers;
tbarController.customizableViewControllers = controllers;
UIView *vistaBarraInferior=tbarController.view;
[window addSubview:vistaBarraInferior];
[window makeKeyAndVisible];
It works, but my problem appears when I would like to go back and exit the ivies with UITabBarController. If I write:
[self.tabBarController.view removeFromSuperview];
[self.parentViewController.navigationController popViewControllerAnimated:YES];
The tab bar is removed from the current view, but I canĀ“t reach the previous view (the root view I had had before doing anything), because I have overwritten it with the 'initWithRootViewController'.
Is it any other way to make it easier or make this work out?
Thanks in advance.
If you want to combine tab bar and navigation bar you must use tab bar as a root and for each tab item add one navigation controller. You can't do it in opposite way as tab bar must be always root.
I am not sure what do you want achieve with bottom bar. Whether it should serve as a tab bar or toolbar. Remember if you use tab bar then each tab will have its own stack of views managed by navigation controller. On the other hand toolbar is related to one view.
If you want to create something like overlay toolbar - something that is always on top of views even if they are animating in and out - you need to choose different solution.
For example you can create your own controller that will display your toolbar at bottom and some container view which content will be managed by navigation controller.
You should use a tabbarcontroller with array of navigation controllers. See apple sample code here for example.
I went through your code and it does not look right on different levels. For example you are calling initwithviewcontroller but passing a uiview. That is not correct.
If I rewrite this code in other way:
UITabBarController *tabBar=[[UITabBarController alloc]init];
tabBar.title=#"MyTitle";
NSMutableArray *items=[[NSMutableArray alloc]init];
MyUIViewController *ld = [[MyUIViewController alloc] init];
[tabBar addChildViewController:ld];
UITabBarItem *tabItem=[[UITabBarItem alloc]initWithTitle:#"Item1" image:[UIImage imageNamed:#"myImage.png"] tag:0];
[items addObject:tabItem];
[tabItem release];
[tabBar setToolbarItems:items];
[self.navigationController pushViewController:tabBar animated:YES];
The result is that the tab bar at the bottom is empty. Have I forgotten to write anything else to show the tab bar item?
If I add a second item, only its title is shown, but neither its image nor anything related to the first item is shown.

Show / Hide tab bar

Everyone
I have a problem and I have been searching the solution but could not find any. I am working on a tab bar based app. Problem is that I want to hide tab bar at first screen and then show it on all other screens that are being displayed after first screen.
Can anyone please give me the best solution for this problem?
Actual scenario is that I have a screen that is login screen. Now i dont want to show tab bar here as tab bar will be displayed only if the user is signed in. When user logs in, I want the tab bar to be displayed showing its contents.
Best Regards
If you have your Tab Bar Controller as your rootController, you can use rootController.selectedIndex =0 for selecting 1st Tab bar Item, and rootController.selectedIndex =1; and so forth.
As soon as that particular view loads, you can load the other views in an array, and then add it to the rootController.selectedIndex and reloadInputViews with animation.
Edit: (as per the comments)
So you have a tab bar controller, and you want to show the introduction and the login screen while starting the App. If login is successful, you want to present the tab bar controller ! This can be done with ModalViewControllers
In the ViewDidLoad of the view that loads up first, (it's your first tab by default), add
//Declare Introduction Screen//
IntroductionController *introductionController = [[IntroductionController alloc] initWithNibName:#"IntroductionController" bundle:[NSBundle mainBundle]];
//Give a navigation screen for your introduction screen and set it to introduction screen
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:introductionController];
navController.title = #"Introduction";
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:NO];
Now your introduction screen would load as soon as your first tab bar loads. But the loading is instantaneous, so it's not visible to the user's eye. Now reference your Login View Controller like #class LoginController and create an object LoginViewController *lvc;, and synthesize it. Now declare LoginButton and in the IBAction
-(IBAction) loginAction: (id) sender{
NSLog(#"I clicked Login");
if (self.lvc ==nil){
self.lvc = [[LoginController alloc] init ];
}
lvc.title = #"Login";
[self.navigationController pushViewController: self.lvc animated:YES];
}
And in the LoginViewController, if Login is successful, just do
[self dismissModalViewControllerAnimated:YES];
create an outlet for the uitabbar, then declare it hidden in the first screen, then create a new void, NOT SENT SO IT DOESNT WORK in the first screen, make it say, lets say, hide. And inside hide, put code saying your uitabbar.hidden = YES; then, to make it work in the other view, write this in the viewDidLoad:
[(//first view*)[UIApplication sharedApplication].delegate //the void, in this case, hide];

iPhone - ModalViewController not raising to top of the screen

I have a UIImagePickerController that is shown
[self presentModalViewController:self.picker animated:NO];
Then later on the code, I allow the user to display a preference panel :
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:#"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
At this point, the new controller raises on the screen, but don't go to the top.
Some space is left "transparent" at the top (I can see the camera view behind), and the bottom of the view is hidden out of the screen. The space I am talking about is about a status bar height. The status bar is not present on the screen.
The navigation controller is hidden :
self.navigationController.navigationBarHidden = YES;
There is a toolbar at the top of the view. Nothing special into the view.
The height of the view is defined at 480. All simulated element are set off in IB.
The autoresize properties are all set on.
I had a previous xib (I rebuilt it from scratch) that worked very well. I don't see what I missed on this one (I have only changed the xib, that replaces the previous one).
I've cleaned the cache to be sure there was nothing left. No change...
I've deleted everything in the new view to prevent some conflicts. No change...
What did I miss ? How could I remove this empty space ?
Try presenting the second modal view controller (the preferences one) from self instead of self.picker
ModalViewController loading on top of another Modal
Edit:
Try setting wantsFullScreenLayout = YES
After some searches and some other problems, I've found a final solution to the problem through this question
I had to call :
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
at the application start.