Nav Bar disappearing on popviewcontroller - iphone

On one of my views, when a button is pressed I call another view that is a SplitViewController. If this SplitViewController is called via one of these buttons I have special objects to add to the view. mostly just nav bar items, like a cancel button. This view can be accessed elsewhere and these items are not needed which is why there is the special condition.
However, when the user is done and i pop the ViewController back to the previous screen that was selected, the nav bar disappears on that screen. I am not setting it to hidden nor am I doing anything strange with the nav bar. Simply adding the SplitViewController then popping back.
Some code..
//declare the split screen VC
SplitScreenViewController *split = [[SplitScreenViewController alloc] init];
//set the flag that this VC is coming from a button, so we need the extra nav bar items
[split setIsFromButton:YES];
[self.navigationController pushViewController:split animated:YES];
now the call back is simply...
- (void)cancelSelectionBtnClicked
{
[self.navigationController popViewControllerAnimated:YES];
}
and when the view returns, the nav bar is gone.
any ideas?
edit it should be noted this exact same thing is done elsewhere the same way(as far as I can tell) and the nav bar is visible on return.

In your ViewController's viewWillAppear you can again make your navigationBar visible.
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO];
}

I have seen various strange navbar behavior in UISplitViewController's, and in a few cases it was because the controller was not set as the rootViewController of the window as opposed to inside a navigation controller like you have set up.

Related

Hide Navigation Bar on one view controller, show it on the pushed one

I have searched a lot but didn't find a solution to my problem.
I have a search bar on my root view controller. When I select it, my keypad appears and I hide (animated) the navigation bar. Now, when I press on one cell, I push a new view controller.The problem is that when I show the navigation bar, it doesn't look natural, it comes from the top, and the pushed view controller comes from the right. I want to do something similar to the email application: the pushed view controller and the navigation bar to come together from the right.
Thank you.
You need to set the navigation bar visible in ViewController A (with Navbar hidden) like this:
-(void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO];
}
and in ViewController B you need to write this code in the ViewDidLoad or ViewWillLoad:
[[self navigationController] setNavigationBarHidden:YES animated:NO];
that's working for me, hope this can help.

Navigation Issue with UITableView

How do I navigate back to the previous page with a UITableViewController. I tried to show a navigation bar with navigation button at the top of the screen, but the navigation bar will not show. I know that you have to give the previous view a title but when I go to do that it does not show anything. Also, since it is a UITableViewController I am not able to drop a navigation bar and add a button to the main view. All I would like to do is display my lists and have the option to navigate back to the previous list with a single button in the upper left corner.
The problem you having with the NavigationController is that your tableViewController is not in the NavigationController hierarchy. Want you want to do this when adding the tableViewController:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourTableViewController];
Then you can do this to add yourTableViewController:
[self.view addSubview:navigationController.view];
If you don't want the navigationBar to appear on the tableViewController just use:
self.navigationController.navigationBarHidden = YES;
in yourTableViewController viewWillAppear method.
When your going to add the view after the tableView you just use:
[self.navigationController pushViewController:someViewController animated:YES];
It's not enough to give the child view a title. You need to give the child view's navigation item a title before you present it. For example, in the parent view, before you push the the view to the navigation stack, do something like this...
[MyChildView.MyNavigationItem setTitle:#"A cool Title"];
For the navigation you are trying to achieve you should be using a UINavigationController. It already has the functionality you describe with the navigation bar and back button built into it.
To move to the next screen (which can be a UITableViewController) you use pushViewController:animated: and to move to the previous screen you use popViewControllerAnimated: (although the built in back button will do this for you).
I suggest reading the UINavigationController class documentation if you are not already familiar with it.

problem with tab bar, not displaying the tab bar upon navigating to that page

In my test project I have some 5 tabs on click of a tab it will go to that corresponding class, on click of back in that screen I will come back to my home page but with out the tab bar.. earlier what 5 tabs were there those are not coming ...
following code I am using under back button
where DataEntry is the class to where i need to navigate
- (void) back_Clicked:(id)sender
{
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithTabBar];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
[self. navigationController presentModalViewController:addNavigationController animated:YES];
}
is I have to add that navigation controller to the tab view? how can I get the tab bar on click of back can any one help me ,thanx in advance
As I understand this, you must already be pushing this view controller either via navigation controller or modally. So the idea would be to simply dismiss it right?
If you have used [self.navigationController pushViewController:animated:] then just do [self.navigationController popViewControllerAnimated:YES]; . This should take you back to the earlier view controller.
If you have presented this modally like you have done here, you should do [self.navigationController dismissModalViewControllerAnimated:YES];.
If you need to return back from a view to the previous view using a back button inside a tab view , i would recommend using a navigation controller inside the view for each tab where you require this functionality. Trying to implement a custom back button without using the navigation controller, in my opinion, is only making things tough for yourself.
If you only want one view to be displayed when you tap on a tab bar button then an ordinary view controller inside the tab bar view should suffice.
The tab bar shouldnt be disappearing altogether unless its been implemented incorrectly.

Designing an Application with different ViewControllers

after reading a lot of tutorials and threads here on stackoverflow there is one basic question left in my head.
The structure of my App should be the following:
MainMenu - fullscreen without a navigation bar but 2 buttons (button1 and button2)
Page1 - should appear by pressing button1 and should have a navigation bar at the top with a "back"-button to get back to the MainMenu.
Page2 - should appear by pressing button2 without a navigation bar at the top. Page2 should be a UISplitView. There must be a back button somewhere.
(I think this is where the problem starts, a UISplitView can't be presented modally, can it?)
You should be able to add subpages to Page1.
So how can I do that? I don't need executable code but just a hint on how the structure of my app should be. For example where to add the navigation controller, how the MainMenu looks like.
Thanks in advance!
Are you trying to create an Application for iPad?
Your Application's UI sems inconsistent being First View the only view without navigation Bar.
You will be using standard navigation to navigate to page1 from home page. So you will be adding a navigation Controller with Home View Controller as a Root View COntroller with hidden navigation bar.
eg.
-(void)applicationDidFinishLaunching:...
{
HomeViewController * hvc = [[HomeViewController alloc]init];
UInavigationController * nvc = [[UINavigationController alloc]initWithRootViewController:hvc];
nvc.navigationBar.hidden = YES;
[window addSubView:nvc.view];
}
Then on tap of first Button you will be pushing the Page1 View Controller
-(IBActtion)button1Pressed:(id)sender
{
Page1ViewCOntroller * p1vc = [[Page1ViewCOntroller alloc]init];
[self.navigationController pushViewCOntroller:p1vc animated:YES];
}
In viewWillAppear: method of Page1ViewController unhide the NavigationBar and hide it in the viewWillDisappear: method
Your Page 2 needs to be splitViewController.
Now about Split View, Apple says
The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface.
But as there is no "must" written in the above statement, and since its finally a View Controller in itselt, you should be able to add it on the window or another view.
Try to create a VIewController, with split VIew added on it, and like page1, push the View on the navigation Controller.

Presenting modal view occasionally hides the navigation bar

I've come across this twice now.
Sometimes using the following line of code:
[self.navigationController presentModalViewController:aViewController animated:YES];
displays the view, but the navigation bar is then hidden.
I can write:
[self.navigationController setNavigationBarHidden:NO];
to my hearts content, everywhere I can think of with no effect.
Has anyone ran into this?
Am I doing something silly?
No, I ran into this as well. The problem is that when you present a modal view controller with a UIViewController based class, it does not extend the calling navigation controller's nav bar onto the modal. The modal view covers the entire screen. What I ended up doing to solve the problem was to create a UINavigationController and push the UIViewController based class onto it, and then do presentModalViewController to the navigation controller's instance.
like:
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentModalViewController:cntrol animated:YES];
[cntrol release];
That allowed me to have a nav bar at the top.
I am not sure if that will help in your particular case, the only other thing I would suggest is to replicate the behavior of the modal with a UIAnimation that stops 44px below the top of the phone. That would keep the original navigation bar visible.
#HeatMiser shows a great way to get around the "bug" surrounding the inability to display items on the nav bar. I'm not sure, however, if this is strictly a bug in Presentation, since modal operations ought to trump the underlying view's interface theme. Having the modal operation's theme mimic the underlying UI theme is fine, but wrapping the true modal view with a navigation view feels wrong to me (extra view object just to get a little more behavior).
Instead, the following worked for me and gives the same behavior as "New Message" does in the Mail program (on the iPhone).
In IB, place a UIToolBar at the top of the modal screen (mimicking the navigation bar) with "Cancel" and "Save" UIBarButtonItem's and a Flexible Space Bar Button Item in between to get the buttons to align left and right. Then, add a UILabel centered over the UIToolBar (The Font Helvetica, Bold, Size 18 appears to match the Navigation Bar Title). Connect the buttons to IBAction's on the modal's UIViewController, and you're done.
If there is a navigation controller active, then you should just use
[self.navigationController pushViewControllerAnimated:how];
to slide another view controller in, while giving yourself and the user into a consistent user interface complete with 'automatic' back button support.
Once a navigation controller is in use, presenting a modal view controller should only be done to enlarge the usable area on the screen. And then, you should really use a fancy animation to let the user know that you are stepping away from the "task" or "steps" that the navigation controller was embodying.
Maybe this is obvious, but once you're done with the modal view and want to dismiss it, you should do something like this in your modal vc:
[parentController dismissModalViewControllerAnimated:YES];
Where parentController is a reference to the vc from where you are presenting the modal view.