Take the 2-minute tour ×

I am using the SplitViewController template. How do I set the title on the topbar in the detailview? Been trying to work this out for hours. Tried simple:

detailViewController.title = @"String";

but no luck.

Any help appreciated. Thanks.

share|improve this question
Looks like the detailViewController contains a toolbar at the top and not a navigationbar. The only way to set the title is to replace this with a navigationbar. –  John Mar 30 '10 at 1:27
There are some good answers here: stackoverflow.com/questions/2754562/… –  Bryan Sep 14 '11 at 21:38
add comment

3 Answers

up vote 1 down vote accepted

Assuming it's a toolbar that you're attempting to add a title to, why not add a UIBarButton with

UIBarButton *barButtonItem = [[UIBarButton alloc] initWithTitle:@"Foo" style:UIBarButtonItemStylePlain target:self action:nil

With a little computation hoop jumping you could figure out the width to place this item somewhere in the middle of the toolbar. Then make it so with a

barButtonItem.width = whatever;

Then add the item to the mutableArray from above and then to the toolbar like

[toolBarArray insertObject:barButtonItem atIndex:x];
[toolbar setItems:toolBarArray animated:YES];

This will work on the iPhone/Touch with the 3.1 SDK, I can't (legally) say anything about the 3.2 until April 3...

share|improve this answer
add comment

The title of the detail view is determined by the either the title of the item in the root view or by content entered in the detail. I don't think its something that you can assign programmatically. You can change the root view title in IB, though.

share|improve this answer
add comment

you need to set it via UIToolbar that is inside DetailViewController. You need to have that UIToolbar to have a BarButtonItem inside it, and reference this BarButtonItem to an IBOutlet of your controller. The template you use dont have BarButtonItem on it by default, you need to add this by yourself. Sometimes you need to add an extra Flixible or Fixed Space Bar item with it.

Once you have it linked on your controller, e.g:

@property (nonatomic, retain) IBOutlet UIBarButtonItem *toolbarItem;

then you can set its title via its title attribute:

toolbarItem.title = @"String";
share|improve this answer
add comment

Your Answer


