Perseus
Perseus

Reputation: 1588

Changing the Leftbarbuttonitem Ttitle

I am using two view controller. I know that when we move to second view controller, the back button title in the Second View Controller will display the First View Controller Title. Now My first View Controller title is Registration, But when I move to the Second View Controller the back should be displayed as "Home". I tried using the following code, but it doesn't change.

self.navigationController.navigationBar.backItem.title = @"Home"; 

Even in the SecondViewController I created my own custom BarbuttonItem like this

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;

But the button looks like a rectangle shape.

Can anyone tell me how to change the Leftbutton item title. ??

Upvotes: 0

Views: 120

Answers (3)

alishaik786
alishaik786

Reputation: 3726

You can do like this also... write this in FirstViewController

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationItem setTitle:@"FirstViewController"];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationItem setTitle:@"Registration"];
    [super viewWillDisappear:animated];
}

Try this one

Upvotes: 0

acorc
acorc

Reputation: 360

Before you push the new ViewController:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
[[self navigationItem] setBackBarButtonItem:backButton];
[backButton release];

[self.navigationController pushViewController:newVC animated:YES];

Upvotes: 1

Pandey_Laxman
Pandey_Laxman

Reputation: 3908

You need to hide BackButton then create your own left UIBarButtonItem

self.navigationItem.hidesBackButton=YES;


UIBarButtonItem *btn=[[UIBarButtonItem alloc]initWithTitle:@"YourCustomTitle" style:UIBarButtonItemStyleBordered target:self action:@selector(yourAction:)];
self.navigationItem.leftBarButtonItem=btn;

If you want to display more UIBarButton in left then you need to create NSMutableArray *arrBarBtn with the capacity then add uibarbutton objects to it.

After that crate UIToolBar then [myToolBar setItems:arrBarBtn];

Final create custom UIBarButton with customView:myToolBar. assign it to self.navigationItem.leftBarButtonItem. if you need code then I will provide.

Upvotes: 1

Related Questions