问题
my first view named "back". I need to hidden the title of the navigationbar because I have my custom navigation bar.
I try with this code but it didn't work!
self.title = @"back";
self.navigationController.navigationItem.titleView.hidden = YES;
回答1:
Just faced the same issue, and doing:
self.title = @"YourTitle";
self.navigationItem.titleView = [[UIView alloc] init];
Did the trick. The next view will have the back button labeled with YourTitle but in the first one, the title won't be shown.
回答2:
If you want to hide entire navigation bar and if you want to use your own navigation bar, you can first hide navigation controller's navigation bar.
[self.navigationController setNavigationBarHidden:YES];
or if you want to only hide title you can do
self.title = @"";
or if you have used custom title view for navigation bar, you can do
self.navigationItem.titleView.hidden = YES;
or if you want to hide back bar button item, you can do
self.navigationItem.hidesBackButton = TRUE;
回答3:
Having the same issue, I just create a fake UIView to populate the titleView property and hide it :
UIView *fakeTitleView = [[UIView alloc] init];
fakeTitleView.hidden = YES;
[self.navigationItem setTitleView:fakeTitleView];
[fakeTitleView release];
Hope it could help.
回答4:
Another option which preserves the back button:
[self.navigationController.navigationBar setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor clearColor]
}];
来源:https://stackoverflow.com/questions/6601768/hiding-title-of-navigationbar