うちのいぬ Tech Blog

Tech Blog of Uchinoinu/My dog

TabBarでタップするTabItemがタップされたらなんかしらの処理を入れたいとき

TabBarControllerのCustom Classを設定

HogeViewControllerとします。

Tab Bar Item に Tag を設定

Screen Shot 2015-08-24 at 10.20.28.png

HogeViewControllerでTagの情報を取得して、処理を入れる

以下な感じでコードを追記します。

override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        switch item.tag {
        case 1:
          println("foo")
        default:
          println("bar")
        }
    }