ios - UITabBarItem 操作不起作用

标签 ios swift uitabbar uitabbaritem

我正在尝试创建一种操作栏,所以我恢复使用标签栏,因为它很干净而且不那么麻烦。所有 5 个选项卡都将执行某种操作,但使用当前代码我没有执行任何操作,我不确定为什么。

我在我的类中添加了 UITabBarDelegate

class DetailViewController: UIViewController, MKMapViewDelegate, UITabBarDelegate

我设置了标签栏

@IBOutlet weak var optionsBar: UITabBar!

这是我希望打印出语句但没有打印出来的代码。

func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        if item.tag == 1 {
            print("Tag one")
        } else if item.tag == 2 {
            print("Tag two")
        } else if item.tag == 3 {
            print("Tag three")
        } else if item.tag == 4 {
            print("Tag four")
        } else if item.tag == 5 {
            print("Tag five")
        }
    }

enter image description here

与数组不同,我将项目标签设置为 1-5 而不是 0-4 但这无关紧要,我很困惑。有人知道为什么当我点击 UITabBarItems 时不打印语句吗?

最佳答案

你可能忘记了

self.optionBar.delegate = self

在 ViewController 的 viewDidLoad 中

关于ios - UITabBarItem 操作不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36455763/

相关文章:

ios - 具有自动调整单元格 (estimatedSize) 和 sectionHeadersPinToVisibleBounds 的 UICollectionView 变得精神起来

ios - SKVideoNode 中的视频在 Xcode 模拟器中工作正常,但无法在大多数设备上播放

ios - Tesseract-OCR 的 OS X 版本?

iOS 8 : Launch Screen StoryBoard appears black [single XIB file works fine]

ios - 快速显示 UIAlertController 中的错误消息数组

iphone - 设置 attributedText 后防止自动 UILabel 字体更改

ios - UITabBar 上的图像被压扁

ios - 当设备被锁定或应用程序处于后台时,App Store 上的应用程序是否可以访问钥匙串(keychain)?

ios - 集中中央标签栏按钮

ios - 空白代替隐藏的标签栏