Storyboard: Views with navigation controller before tabbar - iphone

I have a little problem related to implementing a tabbar with navigationcontrollers, when I have two views before the tabbarcontroller, which also uses a navigationcontroller.
This is my setup in StoryBoard
http://i.stack.imgur.com/8P4Zw.png
http://i.stack.imgur.com/ei3xa.png
But this is not working as I want, because I get two navigationbars (Picture number 2) when I enter the tabbar screen. I know I just can delete the navigation controllers in the tabbar or change the segue to modal, but if I do so, I would not have the ability to add individuel UIBarbuttons to each tabbar view or set individuel navigationbar titles. I would also like to use the push segue through out the app, as it is a kind of an "step by step" app. My question is: How I can eliminate the double navigationbar, when I enter the tabbar, but still have the ability to set a title for each view related to the tab and continue to use the push segue and a navigationcontroller?
I hope you understand my question.

You -can- set individual buttons for each view controller. Grab a tab bar item and drag it to the navigation bar of whichever view controller you want. You can also set the individual title of each view controller. Like you said, there is no reason for the 2nd and 3rd navigation controller you added right after the tab bar controller.

You can set buttons both in the Storyboard and programmatically and they can be different at different stages of your view controller. You should thus delete the second and third navigation controllers and either drag and drop the buttons you want where you need them, and/or deal with it programmatically if necessary.
One example of what you could do programmatically:
UIBarButtonItem *yourButton = [[UIBarButtonItem alloc] initWithTitle:#"yourTitle" style:UIBarButtonItemStylePlain target:self action:#selector(yourSelector)];
self.navigationItem.leftBarButtonItem = buttonSegueBackToAccueil;
This creates a UIBarButtonItem for the controller you are in and places it as the left button of the navigation controller bar. It will run the method "yourSelector" when clicked.

Related

Persistent UIBarButtonItem on all navigation bars within tabbarcontroller

Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.

Trying to add an Edit button to the navigation bar

I had created a xcode project of single view application. I put a tableview and navigation item on my storyboard screen. Now, I bind the array data source to tableview and set the code as below to show edit button on the navigation button.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
However, it seems can't working. I can't find any button on my navigation bar.
Someone can tell me how to make the edit button show?
Thanks!
I put a tableview and navigation item on my storyboard screen.
It sounds like maybe that's the problem. The way to set this up is to start with a UINavigationController as your storyboard's initial controller, and put the UITableViewController in a relation segue from that (as the navigation controller's root view controller). Now if the table view controller says
self.navigationItem.leftBarButtonItem = self.editButtonItem;
the edit button will appear in the navigation bar.
To see an example, start with the Master-Detail template (for iPhone). The Master view controller is structured in the way I'm describing.

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.

iPhone - quick Navigation bar question

I have a UINavigation bar in a few of my views without using a UINavigationController. So i dont use the navigation controller to push new views, I load new views again which have a "static" UINavigationBar at the top.
So currently the navigation bars just show the title of which ever view the user is looking at, they have no other function.
In some of my views I have a requirement to have a back button, about 3 views out of 10.
So I was wondering if it is possible for me to insert a back button that states back and goes back to the previous screen for just these 3 views, so I would have to be able to insert the back button and also detect when it was pressed.
Can I do this with my current set up or do I need to go back and create a view with a UINavigationController and use that to push and pop my views and somehow suppress the back button on the 7 screens that I dont want it to display on?
EDIT:
I've tried the following way:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBackButtonItemStyleBorder target:nil action:selector(myaction)];
[navItem setBackBarButtonItem:backButton]; //Doesn't work
[navItem setLeftBarButtonItem:backButton]; //Works but lacks the back arrow style of the back button
[backButton release];
So I can add a button but it doesn't look like the back button, is there a way to make it look like the back button or should I scratch and just use a UINavigationController? And if I do how can I suppress the back button when I dont want one?
You can if i get you correctly. Just add a custom button to the navigation as leftBarButtonItem or backBarButtonItem and give it a custom button press action. in the button method you can remove this view and show your previous view. But that said the better way is to use normal UINavigationController if your app has Navigation bar in all screens.

Split view controller menu in w/o split view controller?

I am making an iPad app, and am wondering it is possible to get the pop down menu from a UINavigationBar without having to go through the trouble of a split view controller. Is this possible? Tell me if I'm not being specific enough.
Yes, you can do that without much trouble, but you just have to write the code. Just display a UIPopoverController from that UIBarButtonItem on your navBar.
The steps:
Create a UIViewController which manages a table view (or whatever else you want) as your menu view controller.
Add a UIBarButtonItem to your nav bar or toolbar.
Create an IBAction to called something like touchedMenuButton.
Connect that action to that UIBarButtonItem.
In that method, alloc/init that view controller.
alloc/init a UIPopoverController with that view controller.
present that popover from the UIBarButton item
Success!