UITabBarItem操作不起作用

我正在尝试创build一个操作栏,所以我恢复使用标签栏,因为它是干净的,而不是一个麻烦。 所有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") } } 

在这里输入图像说明

不像一个数组我有项目标签设置1-5而不是0-4,但这应该不重要,我很困惑。 有人知道为什么当我点击UITabBarItems时不打印这些语句吗?

你可能忘记了

 self.optionBar.delegate = self 

在ViewController的viewDidLoad中