By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this
In your parent view controller, set the back button when view loads:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"title"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
}
Notice that we don't need to include autorelease
at the end with the latest iOS version.
Hope this helps!
This work better for me. Try :
self.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
The back button pulls its text from the title of the parent view controller.
In the parent view controller (the view controller that appears when you tap the back button), set its own title as the desired text on the back button.
For example, let's say we have a RootViewController
class. When we click a cell in its table view, we push an instance of SecondViewController
. We want the back button of the SecondViewController
instance to read, "Home."
in the viewDidLoad
method of RootViewController.m:
self.title = @"Home";
in the viewDidLoad
method of SecondViewController.m:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
If you want your back button to read, "Back," set the title of the parent view controller to @"Back"
;
And in MonoTouch the following works (in ViewDidLoad of the parent controller):
NavigationItem.BackBarButtonItem = new UIBarButtonItem( "Back", UIBarButtonItemStyle.Plain, null);
If you want not only to change the text of the Back button and remain the original left-arrow shape, but also to do something when user clicks the Back button, I recommend you to have a look around my "CustomNavigationController".
self.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];