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.
Related
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 am having an issue: I have a tab-bar based app. In MainWindow.xib for the tab that shows the nav controller it links to RootViewController.xib.
in RootViewController.xib I have created a navigation controller and have added a table view.
in RootViewController in viewDidLoad i have [self.view addSubview:navController.view];.
The tableview and navigation controller work well for navigation. pressing a cell pushes the controller, and bar buttons work in the pushed controller.
But when I use self.navController.navigationItem.rightBarButtonItem = barButton; nothing shows up at all. also changing self.navController.navigationItem to self..navigationItem ect.. doesn't help. What do you think the problem could be? I appreciate every answer.
fyi the barbuttonitem is setup with:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:#"Help" style:UIBarButtonItemStylePlain target:self action:#selector(help)];
If u want to use both controller navigation and tab bar controller the u check the sample code of apple documentation. In which both function are use so i given link below.
UIcatalogue
If you init the navigation controller with...
navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
Then you can set button with...
rootViewController.navigationItem.rightBarButtonItem = yourButton;
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];
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.
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.