how to change back button title of navigation in iphone - iphone

How to not show Back Bar Button of navigation controller. When I am trying to write my title with " " then this is showing default title name (Root).
How to change it ?

if you don't want to see the back button, use below
self.navigationItem.backBarButtonItem = nil ;
if you want to see your text instead of "Back" button. you could also define your action:.
self.navigationItem.backBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:#"MyOwnBackTitle"
style: UIBarButtonItemStyleBordered
target:self
action:#selector(backClicked:] autorelease];
Use below code to change the bar text,
UINavigationBar *bar = self.navigationController.navigationBar ;
bar.topItem.title = #"MY Title";

Use this in the viewDidLoad method
[self.navigationItem setHidesBackButton:YES animated:YES];

self.navigationController.navigationBar.topItem.title=#"Your Title";

Related

DetailView Page inheriting code from RowView

I have a detailview page, and on top of it the title lable appears to be the title of the row i navigated from. I need to just not display anything in the navigationbar but the title appears and i dont know where to change it.
I also have a backbutton however if i use navigation.backbarbuttonItem then the title of the previous page appears on the button. I want the button to just have back on it. I created a button using leftbarbuttonItem but then the button cannot be styled to look like a backbutton (with one side pointed). It appears as just a rectangular button which i dont like.
Could anyone know how to adjust this?
For number 1, you can just set the viewController title on viewWillAppear or viewDidAppear, lets say
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.title = #"";
}
For number 2, you can use this code to have the "Back" pointy button.
UIViewController *viewController = [UIViewController alloc] init];
// This code
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[self.navigationController pushViewController:viewController animated:YES];

How to change the text on UINavigationBar backButton item?

I know the label on back button item is always the last view clicked, but how should I go if I want to have "back" text on it?
self.navigationItem.backBarButtonItem =[[[UIBarButtonItem alloc]
initWithTitle:#"Your Title"
style:UIBarButtonItemStyleBordered
target:nil
action:nil] autorelease];
This issue bugs me as well. My hack is to change the title of the view controller in -viewWillAppear: and -viewWillDisappear:, where the latter changes the title to what will appear on the "back" button and the former changes it back to what I want the title of that screen to be. For example,
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
myViewController.navigationItem.title = #"My Title";
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
myViewController.navigationItem.title = #"Back";
}

navigationItem.backBarButtonItem not working? Why is the previous menu still showing as the button?

Trying to customize my back button in a drilldown navigation controller.
On my one view controller I have an Add button where the code programatically generates a new UIViewController:
- (void)add:(id)sender
{
MyAddViewController *addController = [[MyAddViewController alloc] initWithNibName:#"MyAddViewController" bundle:nil];
[self.navigationController pushViewController:addController animated:YES];
[addController release];
}
This works and when I click the add button it drills down into the new view. Inside the viewDidLoad method of MyAddViewController.m I have:
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
But this isn't working. The back button in the navigation controller remains the title of the previous view's controller on the stack. It seems that line does nothing. Did I miss something?
Thanks
self.navigationItem.backBarButtonItem is for the back button that appears on the view pushed by the view controller. So you need to move that line to the previous view controller.
This will only work on each child after the viewController that has self.navigationItem.backBarButtonItem.
You're confusing the backBarButtonItem and the leftBarButtonItem. From the UINavigationItem docs on backBarButtonItem:
When this item is the back item of the
navigation bar—when it is the next
item below the top item—it may be
represented as a back button on the
navigation bar. Use this property to
specify the back button. The target
and action of the back bar button item
you set should be nil. The default
value is a bar button item displaying
the navigation item’s title.
So, if you were to change:
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
To:
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
I believe you would get the desired effect.
You can't replace the backBarButtonItem, but you can use the leftBarButtonItem to override it. But to get the new button to perform operate the same as the back button, you do need to set the target and action of the new button something like:
- (void)dismissMyView {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:#"Quit" style: UIBarButtonItemStyleBordered
target:self action:#selector(dismissMyView)];
}
If ViewController A push ViewController B meanwhile we want to set the back bar button tittle, we should set "self.navigationItem.backBarButtonItem = ..".if it was set in ViewController B, it will not work as we want.

screen naviagation iphone, xcode?

i'm having 3 screens
set title to screen1 using
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title =#"Products";
}
when navigation to next screen (screen2) second screen having the title "Categories"
but there is a button on the top name "Products" to Screen1
i want to change the button name as "Back"
Please tell me how?
triedself.navigationItem.leftBarButtonItem .title = #"Back";
See these two:
How to set the text of a back button on a UINavigationBar?
How do I change the title of the "back" button on a Navigation Bar
Solves your problem.
UIBarButtonItem *item=self.navigationItem.leftBarButtonItem;
item=[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem=item;
[item release];
Put this code in your first scree viewDidLoad method as it is It really works.
You have to do something like the follows to set the text of the back bar button to something other than what the previous view was named:
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
barButton.title = #"Your Custom Title";
self.navigationItem.backBarButtonItem = barButton;
You CANNOT do the following:
self.navigationItem.backBarButtonItem.title = #"Your Title";
This sets the previous view on the stack to "Your Title" and not was it was before.

Back button on UINavigationController

I know that it could seem strange but i need to add a back button on the navigation Bar of the first navigationController's view. I tried like this:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Foo" style:UIBarButtonItemStyleBordered target:self action:#selector(foo:)];
self.navigationItem.backBarButtonItem=backButton;
if instead of backBarButtonItem i write leftBarButtonItem the button is showed. My problem is that i need an arrow button as the normal back button. Is this possible?
Usually this works out of the box, but sometimes with modal views / action sheets you may need this. Just before you instantiate your viewcontroller and push it onto navigationcontroller stack, try
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: #"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
[[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];
DetailViewController *detailVC = [[DetailViewController alloc]init];
[self.navigationController pushViewController:detailVC animated:YES];
[detailVC release];
I don't think you can do that on the first NavigationController view, because you need to set the backBarButtonItem property in the parent controller, before the child controller is pushed. Also, according the to the Apple docs, the target & action of the backBarButtonItem must be nil.
This question about creating a left-arrow button on a UIToolbar may give you some ideas of how you could work around this using a custom image (for the leftBarButtonItem).
or you could also do the following - I prefer this method. I got this from a different post.
Use following psd that I derived from http://www.teehanlax.com/blog/?p=447
http://www.chrisandtennille.com/pictures/backbutton.psd
Then I just create a custom UIView that I use in the customView property of the toolbar item.
Works well for me.
Hope that helps a little
Of course you can do this. You just need to change the leftBarButtonItem's title to back
then you will get a nice left arrow button with the title back. Then you just change the selector to actually perform a method when the button is clicked. So #selector(foo:)
Here some code on how to achieve the above:
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
self.navigationItem.leftBarButtonItem.title = #"Back";
self.navigationItem.leftBarButtonItem.target = self;
self.navigationItem.leftBarButtonItem.action = #selector(endTextEnteringButtonAction:);
Let me know if that helps.
Apple Document says:
When this navigation item is immediately below the top item in the stack, the navigation controller derives the back button for the navigation bar from this navigation item.
So If your navigation item is the top of the Stack (as we are talking here) you can't add the back button to the navigation controller, simply because no place he can navigate back to it because it's the top item in the stack.
Updated Answer :
After I searched I found work a round to make a back button in your root view controller in Navigation controller in these link
It's very simple :)
[self.navigationItem setHidesBackButton:YES animated:YES];
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:#"Start" style:UIBarButtonItemStyleBordered target:self action:#selector(initializeStuff)];
self.navigationItem.leftBarButtonItem = backButton;