mvasco
mvasco

Reputation: 5101

Setting navigationItem title

In my app I am using storyboard, I need to change the title on a viewController. I am doing it as follows. In the .h file:

@property(weak, nonatomic) IBOutlet UINavigationItem *navBar;

And in the .m file:

@synthesize categoriaDescription,navBar;
...
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *category = self.categoriaDescription;

    NSLog(@"Value of category = %@", category);

    [self.navBar setTitle:category];

...

The default title is not changed, it should be 'A', the value of 'category' in this case. The Log shows 'A'.

Any help is welcome.

Upvotes: 0

Views: 83

Answers (2)

kas-kad
kas-kad

Reputation: 3764

Why don't you simply use NavigationController?

realize that viewController.navigationItem does not have any sense if the viewController does not belongs to the navigationController's stack

Upvotes: 3

user2573339
user2573339

Reputation: 138

[self.navigationController setTitle:@"myTitle"];

This should work.

EDIT: If you do not have a navController on your storyboard

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];
[navController setTitle:@"myTitle"];

[self.view addSubview:navController.view];

Upvotes: 1

Related Questions