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

标签 ios iphone swift uitabbarcontroller

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.

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

最佳答案

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

  1. 开始使用 UITabBarController 作为初始 View Controller
  2. 使用presentViewController代替pushViewController
  3. 使用模态Storyboard segue 执行模态演示
  4. 动态更换rootViewController

初始 View Controller 设计

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

enter image description here


推送设计

另一个导航 Controller 初始 View Controller ,使用 5 个自适应 Action Segue 之一:

  • 显示
  • 自定义

-> 没有 Edit 按钮,因为它与父 UITableViewController 直接冲突。

  • 显示详细信息
  • 模态呈现
  • 弹出式呈现

-> Edit 按钮按预期显示。

enter image description here


代码

<强>1。程序模式

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

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

<强>2。 Storyboard模态

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

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

<强>3。根交换

一个更激进的解决方案涉及在 window 级别换出 Root View Controller :

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

结论

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

关于ios - 编辑按钮未显示在 UITabBarController 的 MoreNavigationController 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31767022/

相关文章:

ios - 如何使 UIView 动画序列重复和自动反转

ios - 将错误的图片上传到我的 Firebase 存储

ios - ios中的多个单选按钮

iphone - 如何查看 iPhone 模拟器的钥匙串(keychain)

iphone - iOS:查找具有相同标签的所有控件

arrays - 在 Swift 2 中从 segue 展开后 Tableview 不重新加载

ios - Swift - 如何在 SQLite 查询中捕获 nil 值?

ios - 核心数据 64 位转换

ios - 如何在 UIScrollView 的内容周围绘制边框?

objective-c - 使用委托(delegate)通过多个 View Controller 传回数据