Display title for view in back button but not in navigation bar

I would like to set the title of my view to "Main Menu", however, I do not want the title to appear in the navigation toolbar. The reason I want to set the title is so the back button has the title "Main Menu". Is there a way to do this? Here is the relevant code:

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        self.title = @"Main Menu";
        // Custom initialization

    }

    return self;
}

Answers


To set the title of back button item, you should write in viewDidLoad method as follows:

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Main Menu"
 style:UIBarButtonItemStyleBordered target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButtonItem;
    [backButtonItem release];
}

I would set the back button for this one. You need to set the value of the back button in the Main Menu controller before it pushes the next UIViewController.

For an explanation of why check out my previous answer and the docs for View controller programming guide


Set the title right before you push the next view controller:

[[self navigationItem] setTitle:@"Main Menu"];
[navigationController pushViewController:nextVC animated:YES];

and set it to a blank string (or nil) in viewWillAppear:

[[self navigationItem] setTitle:@""];

Need Your Help

Swift, sprite kit game: Have circle disappear in clockwise manner? On timer?

swift timer xcode6 sprite-kit

Alright, so I don't know the name for this but I have a sprite kit game (a runner game) that, when it's game over, is going to have a "save me" button and a timer that runs out accordingly. When the

How to get the element of data attribute value using jquery?

jquery

Consider the following, how do get the last element of a particular data attribute value?