编辑按钮未显示在 UITabBarController 的 MoreNavigationController 中

Edit button not displayed in UITabBarController's MoreNavigationController

一个UITabBarController被压入堆栈:

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

出现后,更多选项卡按钮会正确显示,但重新排列选项卡栏的编辑按钮不会。根据 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.

我的猜测是标签栏不适合在导航控制器中使用。关于恢复编辑按钮有什么想法吗?

原因是您的演示者的导航栏与更多部分的导航栏重叠。

如果您不显示导航控制器的导航栏,您将能够再次看到编辑按钮您点击 更多 选项卡。

您可以同时拥有 UINavigationControllerUITabBarController ;使用 Storyboard 有助于更好地理解问题,这些解决方案中的任何一个都有效:

  1. 开始使用 UITabBarController 作为 初始视图控制器
  2. 使用presentViewController代替pushViewController
  3. 使用模态 Storyboard segue 执行模态呈现
  4. 动态换出 rootViewController

初始视图控制器设计

当Tab Bar Controller 初始View Controller时,Edit按钮正常显示。


推送设计

另一个导航控制器初始视图控制器,使用5个自适应动作Segue之一:

  • 显示
  • 自定义

-> 没有 Edit 按钮,因为它与父 UITableViewController.

直接冲突
  • 显示详情
  • 模态呈现
  • 弹出式呈现

-> 编辑 按钮按预期显示。


代码

1。程序模式

使用问题中提供的确切代码,更改最后一行:

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

2。故事板模式

保持 Storyboard 主题,创建一个正确类型的 segue,分配一个标识符(即 presentModallySegue),上面的 5 行变成这个 单行:

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

3。根交换

一个更激进的解决方案涉及在 window 级别换出根视图控制器:

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

结论

要么更改您的设计以采用 Tab Bar Controller 作为初始 View Controller,要么 modally 呈现 Tab Bar Controller。