Setting the title "More Navigation Controller" titleView

I am surprised that they did not ask "more" about this :-)

My application is a standard tab bar controller with multiple sections. Each section (tab) contains a navigation controller that controls several view controllers (your basic view type is tableview + detailview). Now that I have added the 6th tab, iOS creates the Advanced tab, which manages the last two tabs. I need to remove the text “More” in the middle of the navigation bar (Note: not the button text, nor the title of the tab itself), and also apply a custom background image to the navigation bar.

Note. This question is about setting up the More navigation bar. I successfully changed the background image and the title text on all the navigation bars created outside of iOS.

In my application application, the application develops as follows:

Create view controllers:

ViewController1 *vc1 = [ViewController1 alloc] initWithNibName@ "View1" bundle:nil]; vc1.title = @"VC1"; vc1.tabBarImage.image = [UIImage imageNamed:@"image1.png"]; 

Repeat the above procedure 5 more times for controllers of the form vc2-vc6.

Create separate navigation controllers:

 UINavigationController *nc1 = [UINavigationController alloc] initWithRootViewController:vc1]; 

Repeat 5 more times for nc2 - nc6 navigation controllers.

Add Nav controllers to tab bar controller

 self.tabBarController.viewControllers = [NSArray arrayWithObjects: vc1, vc2, vc3, vc4, vc5, vc6, nil]; 

All code above works fine. No problems.

Then I add a custom background image to the navigation controller More:

  if (self.tabBarController.moreNavigationController){ if ([self.tabBarController.moreNavigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) { UIImage *image = [UIImage imageNamed:@"navlogo.png"]; [self.tabBarController.moreNavigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; } else { UINavigationBar *navbar = self.tabBarController.moreNavigationController.navigationBar; UIImage *headerImg = [UIImage imageNamed:@"navlogo.png"]; [navbar setBackgroundImage:headerImg forBarMetrics:UIBarMetricsDefault]; } } 

This also works great. No problems

Since my custom background contains the dead center of the customer’s logo, I need to remove the titleView text, which reads “More” by default. Notice I'm not talking about the text DIRECTION BUTTONS, but the label in the middle of the navigation bar.

Logically, one could assume that this would work:

  UILabel *label = [[UILabel alloc] init]; label.text = @""; self.tabBarController.moreNavigationController.navigationItem.titleView = label; 

... because I do this in all individual view controllers, replacing self.navigationItem.titleView with self.tabBarController.moreNavigationController, etc.

But that will not work! I can successfully change both the background image and the titleView text on all of my navigation controllers using this same code (again, replacing self.navigationController.navigationItem with moreNavController material ...). However, in the application delegate, I can only set the background image, but not the titleView of the More navigation controller More.

Any solutions would be very helpful.

B. B.

+4
source share
6 answers

Turns out my original code was right, just in the wrong place.

 UILabel *label = [[UILabel alloc] init]; label.text = @""; self.tabBarController.moreNavigationController.navigationBar.topItem.titleView = label; 

However, I did this before before adding tabBarController as my rootViewController

The correct order is:

 self.window.rootViewController = self.tabBarController; UILabel *label = [[UILabel alloc] init]; label.text = @""; self.tabBarController.moreNavigationController.navigationBar.topItem.titleView = label; 
+1
source

For example, in the application: didFinishLaunchingWithOptions: template iOS template Tab

 // Override point for customization after application launch. UITabBarController *tabBarController = (UITabBarController *)(self.window.rootViewController); UINavigationController *moreNavigationController = tabBarController.moreNavigationController; moreNavigationController.navigationBar.topItem.title = @""; 

This changes the title of the navigation bar, but leaves the title of the tab label as "More."

0
source

I found one

Swift 2.2

Put it in doneFinishLaunchingWithOptions

 tabBarCtr.moreNavigationController.delegate = self tabBarController.moreNavigationController.viewControllers.first?.title = "" 

Implement this delegate method

 func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) { navigationController.navigationBar.topItem?.rightBarButtonItems = nil navigationController.viewControllers.first?.title = "" } 

It will also remove the edit button on top of the navigation bar of the navigation controller.

0
source

Publishing the Swift5 version, as it took me quite a while to get it working properly

 moreNavigationController.viewControllers[0].tabBarItem = UITabBarItem(title: "My Title", image: UIImage(named: "MoreTab")!, tag: 1111) moreNavigationController.navigationBar.topItem!.title = "My Title" 

Note that changing moreNavigationController.tabBarItem does not work quite well. I do this in the viewDidLoad () of a class that extends the UITabBarController

0
source

This may not be applicable to everyone in the stream, but for me ... I had a tabBarController s> 5 elements ... I needed to set the title on the automatically generated moreNavigationController ... it was as simple as specifying self.title = @ " title "in the viewDidLoad method of the target detailview controller.

-1
source

You can change the title inside the viewDidLoad function

 self.title = @"" 
-3
source

All Articles