UINavigationController subclass won't set titleView on load

本秂侑毒 提交于 2019-12-25 02:28:43

问题


I've just created a simple subclass of UINavigationController.

#import "TTNavigationController.h"

@implementation TTNavigationController

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIImage *logo = [UIImage imageNamed:@"logo"];
    UIImageView *logoView = [[UIImageView alloc] initWithImage:logo];
    self.navigationItem.titleView = logoView;
}

But when I run the project the navigation bar has not the titleView with the logo.

Otherwise if I try to move those 3 lines of code in viewDidLoad of my view controller works fine. Why?


回答1:


You can't use self.navigationItem because the navigation controllers own navigationItem is never used. It has this property because it is a type of view controller but it isn't actually displayed because the viewControllers (or, more specifically, the topViewControllers) navigationItem is displayed.

So, change the view controller navigationItem (either directly, or when it is pushed).



来源:https://stackoverflow.com/questions/20922970/uinavigationcontroller-subclass-wont-set-titleview-on-load

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