Is it possible to set navigationitem.title from a view's NIB?

﹥>﹥吖頭↗ 提交于 2019-12-11 07:42:41

问题


I am loading a new view from a NIB (initWithNibName) and then I am pushing it into navigation controller stack (pushViewController).

In order to have a proper "Back" button each view should have a title. Unfortunately I didn't manage to find a way to set up View Title in the Interface Builder.

It can be done in run time:

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"MyTitle";  
}

But I didn't manage to do it in design time in the NIB.

Is there a way of doing it?

Thank you.


I just realised my question is not 100% correct.

In fact I am looking for a way to set ViewController's title via NIB.

And UIView in the NIB is different from the UIViewController (which got the title property I am trying to change).

So my question was ... about something different. :)


回答1:


You should be able to access the root view controller's navigation item through the navigation controller item. The root view controller's navigation item has the property title that you can access in IB.

maybe this picture helps (your basically clicking on the blue navigation bar to put focus on the navigation item):



来源:https://stackoverflow.com/questions/7418511/is-it-possible-to-set-navigationitem-title-from-a-views-nib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!