6

I wrote a Master/Detail Application by using the Master/Detail template of XCode. After starting the app, the title of the navigation button for the master view is just "Master". Now I waant tio rename that button, but unfortunately I don't know how to access this button. In appdelegate.m there is the following code to initialize the views:

MasterViewController *masterViewController = [[MasterViewController alloc] init];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]

I tried these ways without success:

masterViewController.navigationItem.title = @"newTitle";

or

masterNavigationController.navigationItem.title = @"newTitle";

As I wasn't sure, if the name of the button is just the title of the view behind idt, I also tried that:

masterViewController.title = @"newTitle";

Nothing worked. But as the title of the button is "Master" and I definitely didn't set it, I believe there must be some way to set it. Does anyone know how to do it?

Just to show the button: enter image description here

usermho
  • 207
  • 4
  • 11
  • The navigation button? Are you talking about the back button? – SEG Dec 22 '12 at 17:06
  • Maybe... I really don't know if it is the back button or the navigation button. It is the only button that appears after the app is started. I can use it to make the MasterView appear. – usermho Dec 22 '12 at 17:21

4 Answers4

6

If you would have created Master/Detail application using Master/Detail Template, then go to your "MasterViewController.m" file and change the string "Master" as you wanted. See the below image it would be like this in your MasterViewController.m. enter image description here

UPDATE: and also change the barButtonItem name in the DetailViewController.m as like below. This will do the trick. enter image description here

Dinesh Raja
  • 8,501
  • 5
  • 42
  • 81
  • That was exactly what I did. But meanwhile, I changed my init method and inside it I set the title with a simple string: self.title = @"newTitle" And this only changes the headline in the view but not the title of the button! – usermho Dec 22 '12 at 18:35
1

try self.navigationItem.title = @"newTitle"; inside viewDidLoad() of MasterViewController.m file. or self.title = @"newTitle" inside the init() method. HTH.

batman
  • 1,937
  • 2
  • 22
  • 41
1

I assume that you are trying to change the title of the back button property. This is done by putting the following code in the -viewDidLoad method of MasterViewController.

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"newTitle" style:UIBarButtonItemStyleBordered target:nil action:nil];
SEG
  • 1,717
  • 1
  • 18
  • 33
0

It's been a while and somehow with the current Xcode Version 8.3.2 it works different:

If you would have created Master/Detail application using Master/Detail Template, then go to your Main.storyboard and select the Master in the Master Scene and then show the "Attributes Inspector". In the Navigation item area you can change the Title.

You can do this for Master as well as Detail. enter image description here

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92