UITabBarItem action not working

我只是一个虾纸丫 提交于 2019-12-07 12:47:54

问题


I am trying to create a sort of action bar so I restored to using a tab bar because it is clean and is less of a hassle. All 5 of the tabs will be doing some kind of action but with the current code I have it is not doing anything and I am unsure why.

I have the UITabBarDelegate added in my class

class DetailViewController: UIViewController, MKMapViewDelegate, UITabBarDelegate

I have the tab bar set

@IBOutlet weak var optionsBar: UITabBar!

And this is the code I was hoping would print out the statements but is not.

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")
        }
    }

Unlike an array I have the item tags set 1-5 instead of 0-4 but that should not matter, I am very confused. Does anybody know why this is not printing the statements when I click on the UITabBarItems?


回答1:


You might be forgetting to

self.optionBar.delegate = self

in viewDidLoad of the ViewController



来源:https://stackoverflow.com/questions/36455763/uitabbaritem-action-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!