In an iPhone app I want to have a navigation button on the right side of the navigation bar of the root navigation controller. However this right button disappears every time I push another viewController on top of the navigation controller and the right slot becomes empty. How can I make sure it remains on its proper place. I am using Interface Builder.
The "View Controller Programming Guide for iOS", as I understand it, says that the new viewController I'm pushing has to have its navigationController property set to the current navigation controller, however this property is readonly. How can I achieve this?
This is the thing with Navigation controller
The left bar button is taken Automatically by the iOS for All viewControllers
But you have to design the Rightbarbutton for the Specific ViewController
So for each ViewController in ViewDidLoad
UIBarButtonItem *rightCornerButton = [[UIBarButtonItem alloc]
initWithTitle:#"Client Profile"
style:UIBarButtonItemStylePlain target:self
action:#selector(onTouchRightBarButton:)];
[self.navigationItem setRightBarButtonItem:rightCornerButton];
[rightCornerButton release];
Related
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.
Does anyone have any tips for this scenario.
My app delegate's nib has a viewcontroller set as the rootviewcontroller, so it loads this view controller when the app loads.
This viewcontroller has a toolbar with various buttons. These buttons are meant to switch between different view controllers.
I have tried using addChildViewController, presentViewController, presentModalViewController nothing allows me to switch between view controllers BUT still keep the toolbar visible.
If I use addSubView then all the orientation stuff goes mental and I have to resize the view controller manually which doesn't seem like something I should be doing.
EDIT: I want to keep the nav controller's button visible even when pushing controllers on i.e. if I have an EDIT and DELETE button I want those same buttons to remain on the toolbar even when I push different controllers onto the stack
It sounds like you should be using a tab bar.
Alternatively, you should be using a navigation controller with a toolbar and push/pop view controllers on this when the toolbar buttons are pressed:
Please note the navigation bar does not have to be visible if you use a navigation controller.
//create first button
buttonOne = [[UIBarButtonItem alloc] initWithTitle:#"EDIT" style:UIBarButtonItemStyleBordered target:self action:#selector(editStuff)];
[buttons addObject:buttonOne];
//create second button
buttonTwo = [[UIBarButtonItem alloc] initWithTitle:#"DELETE" style:UIBarButtonItemStyleBordered target:self action:#selector(deleteStuff)];
[buttons addObject:buttonTwo];
// Add buttons to toolbar and toolbar to nav bar.
[buttonsToolbar setItems:buttons animated:NO];
[buttons release];
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:buttonsToolbar];
self.navigationItem.leftBarButtonItem = twoButtons;
[twoButtons release];
addSubview: doesn't permit use of a secondary view controller, so that's not ideal.
You can use a toolbar with bar buttons to switch view controllers, but the simplest implementation is to have identical toolbars in each view controller's nib, and make the view controllers subclasses of a superclass that handles all of the toolbar actions.
There is no need to use a tab bar or navigation bar, although either of these would be a simpler approach in someways (but less obvious in the ways that matter).
Use a UITabBarController as your root controller. This acts as a parent container for your child viewcontrollers, provides a tab bar and implements switching between child views. Check out the class reference or the View Controller Programming Guide
I have a Navigation Controller in my app delegate that i am using to switch between views and that seems to work fine clicking the back button in the NavigationBar, but only when i have a UITable in the mix. But when i pushRootviewController to a standard root view controller i still see the back button in the UINavigationBar but when i click it the program quits and logs no errors.
I thought maybe something like this would work, but no luck.
CoCoachAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIBarButtonItem *iButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleBordered target:self action:#selector(playThis:)];
appDelegate.navigationController.navigationItem.backBarButtonItem = iButton;
[iButton release];
Anyone have something similar happen? Any ideas?
Thanks!
Your problem is that you set the button to the navigation controller itself. you should be setting the button to the navigationItems of your Controllers inside your Navigation Controller (and remember that the backBarButtonItem is displayed on the navigation bar when the next (follow-up) view controller is visible. if that is not the behaviour you want, you should use leftBarButtonItem.) also remember that "back buttons" should have target/action set to nil as the navigation controller adds itself als target when you use it as backBarButtonItem.
I have a navigation view controller and there are 3 view controllers in the navigation stack. Now on the third and top most visible view controller I have a default back button coming in.
I need to bring this view controller in edit mode which I did... Now the requirement is to have a cancel button as the left bar button item instead of back button.
This is similar to the functionality given by contacts application of iPhone where you edit a particular contact.
Any clue how to achieve this?
To hide back button and add a left bar button use-
[self.navigationItem setHidesBackButton:TRUE];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector()];
[self.navigationItem setLeftBarButtonItem:leftBarButton];
[leftBarButton release];
And then to programmatically return to the previous view controller, you can do-
[self.navigationController popViewControllerAnimated:YES];
This is a simpler way:
[self.navigationItem setHidesBackButton:YES];
If you are using storyboard, you can also just drag a bar button item onto the navbar where the back button would normally show up. This will override it.
I have a reference to a "UIBarButtonItem", is there a way I can add a custom "Back Navigation Button" to that item when it is not part of a Navigation based view?
I can add a left button:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"Custom Back"
style:UIBarButtonItemStylePlain target:self
action:#selector(backAction:)];
menuItem.backBarButtonItem = backButton; //This doesn't seem to work.
menuItem.popOverNavigationItem.leftBarButtonItem = backButton; //This shows a normal button
So how could I make the leftmost button look like a back navigation button?
UPDATE: This other question answered the root of my problem that was leading me to try and do this non-standard UI setup:
iPad: Merge concept of SplitViewController and NavigationController in RootView?
I think the correct way to set the back button is to set it for the view controller that you would be going back to. For example:
RootViewController > DetailViewController
If you want the back button to say "Custom Back" whilst you're on DetailViewController, you have to actually set RootViewController's back button to "Custom Back".
Hope that makes sense.
Having just struggled with this: I think the answer is “no.” You'll need a controller hierarchy.