Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit button not displayed in UITabBarController's MoreNavigationController

A UITabBarController is being pushed onto the stack:

let presenter = presentingViewController as! UINavigationController
let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
presenter.pushViewController(tabvc, animated: true)

Once presented the more tab button correctly shows, but the edit button to rearrange the tab bars does not. According to the docs on the MoreNavigationController:

The interface for the standard More item includes an Edit button that allows the user to reconfigure the tab bar. By default, the user is allowed to rearrange all items on the tab bar. If you do not want the user to modify some items, though, you can remove the appropriate view controllers from the array in the customizableViewControllers property.

My guess is that the tab bar is not happy being in a navigation controller. Any ideas on bringing the edit button back?

like image 550
memmons Avatar asked Aug 01 '15 23:08

memmons


2 Answers

You can have both a UINavigationController and a UITabBarController ; using Storyboard helps understand the issue better, any of these solutions will work:

  1. Start out with a UITabBarController as initial view controller
  2. Use presentViewController instead of pushViewController
  3. Use a modal Storyboard segue to perform a modal presentation
  4. Swap out the rootViewController dynamically

Initial View Controller Design

When the Tab Bar Controller is initial View Controller, the Edit button is displayed normally.

enter image description here


Pushed Design

Another Navigation Controller is initial View Controller, using one of 5 adaptive Action Segue:

  • Show
  • Custom

-> No Edit button, since it is in direct conflict with the parent UITableViewController.

  • Show Detail
  • Present Modally
  • Popover Presentation

-> Edit button displayed as expected.

enter image description here


Code

1. Program Modal

Using the exact code presented in the question, change the last line:

let presenter = presentingViewController as! UINavigationController
let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
presenter.presentViewController(tabvc, animated: true, completion: nil)

2. Storyboard Modal

keeping with the Storyboard theme, create a segue of the correct type, assign an identifier (i.e. presentModallySegue) and the 5 lines above become this single line:

self.performSegueWithIdentifier("presentModallySegue", sender: self)

3. root Swap

A more drastic solution involves swapping out the root view controller at the window level:

let tabvc = UITabBarController()
tabvc.viewControllers = vcs
tabvc.customizableViewControllers = vcs
self.view.window!.rootViewController = tabvc

Conclusion

Either change your design to adopt the Tab Bar Controller as the initial View Controller, or present the Tab Bar Controller modally.

like image 128
SwiftArchitect Avatar answered Nov 05 '22 23:11

SwiftArchitect


The reason is that navigation bar of your presenter overlaps with the navigation bar of More section.

If you don't show the navigation bar for you navigation controller, you will be able to see the Edit button again when you tap on the More tab.

like image 20
Vikas Dadheech Avatar answered Nov 05 '22 23:11

Vikas Dadheech