views:

1090

answers:

3

Hi, I have a RootViewController and a SubViewController. I traverse the views in either direction. The RootViewController is a UITableView SubClass. Depending upon the row selected I want to change the title of the subview using self.navigationItem.title = [chunks objectAtIndex:1];

It works when the subview is first time loaded. But when I return to the RootViewController and load the subview again the previous title persists. Any ideas what am I missing out on?

A: 

I just tried it in an app of mine. When I set the title using

self.navigationItem.title = @"Foo"

the name in the navigation bar changes instantly. I think you have a bug somewhere else that you code is only getting called the first time you invoke your SubViewController. Stick a break point on that line and see if it actually gets called a second time. Or perhaps [chunks objectAtIndex:1] is always returning the same string.

Or perhaps I'm not understanding your question. As far as I can tell it does work like you are expecting it to.

Squeegy
+1  A: 

In your particular case, you probably want to set your title in viewWillAppear: so that the title gets set every time the view comes on the screen.

August
I had the same issue and this is what worked for me, FWIW. It still feels a bit "hacky" to me.
Prairiedogg
A: 

I guess you are trying to change the title in the viewDidLoad method. The viewDidLoad is called only the first time the view is loaded. In case you are reusing the same viewcontroller's instance, viewDidLoad will be called only once.

Instead try setting the title in viewWillAppear method. This method is called every time the view is going to be displayed. That should work.

lostInTransit