ios - tabBarController 上的 barButtonItem

标签 ios swift uitabbarcontroller uitabbar uitabbaritem

我想将 barButtonItem 添加到 tabBar 上,这样我就不必在屏幕顶部使用导航 Controller 。

我的 ViewController 嵌入到 tabBarController 中:

enter image description here

我想在每个 View Controller 上添加一个 barButton 例如:

enter image description here

他们实现了一些代码,例如:

    func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        if item.tag == 4 {

        }
    }

点击此按钮时运行函数。

问题是构建应用程序时此按钮未显示在 tabBar 上。

enter image description here

我希望这无需创建自定义 tabBar 即可实现。

最佳答案

我不太明白你所描述的问题是什么。您是否尝试仅使用 UITabBarController 在屏幕右上角添加“注销”按钮?你为什么反对使用 UINavigationController?使用 Storyboard(看起来您正在使用)来实现非常容易。

Apple 甚至有一个关于如何在 UITabBarController 中实现 UINavigationController 的页面:https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html

此处的关键信息:

To create a combined interface with three tabs that contain custom view controllers and one tab that contains a navigation controller:

  1. Create three custom view controllers, one for each tab, and a navigation controller.
  2. Select the three custom view controllers and the navigation controller (only the navigation controller scene, not it’s root view controller).
  3. Choose Editor > Embed In > Tab Bar Controller.
  4. Display the tab bar controller as the first view controller by selecting the option Is Initial View Controller in the Attributes inspector (or present the view controller in your user interface in another way.)

关于ios - tabBarController 上的 barButtonItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41602608/

相关文章:

ios - 如何以编程方式使用 UITabBar

ios - 为什么Tabbar选中项总是0?

ios - parse.com 如何测试解析数据类 iOS 中是否存在列

ios - CADisplayLink 目标选择器在失效后被触发

ios - 在 xamarin.ios 中更改 imagePicker 布局

ios - 应用程序未通过代码设计验证。签名无效,包含不允许的权利

swift - 如何从 Swift 中的 AppDelegate 引用当前的 SKScene

swift - 快速解析 JSON 抛出 'fatal error: unexpectedly found nil while unwrapping an Optional value'

swift - .Element 含糊不清地使用 Element SWXMLHash swift

ios - 在不同的选项卡中弹出 View Controller