问题
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 topViewController
s) 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