2014年7月3日木曜日

UITabBar上で、どのtabitemが選択されたか判別する

tabitemっていい方でいいんだっけ。tabbaritemかもしれん。

複数のタブが存在し、且つ各タブのUIViewControllerが同じクラスに紐付いている場合、
どのタブがタップされたか判別して表示切り替えたいわけですけど、どうするか。

以下自己流。ましな方法ないのかしらーとは思うが。

- (void)viewDidAppear:(BOOL)animated

{

    //方法1 vcのタイトルにフラグ値でも設定しておく。文字列でもよいか

    int mode1 = [self.tabBarController.selectedViewController.title integerValue];

   

    //方法2 vcのviewのtagを使う。数値。

    int mode2 = self.tabBarController.selectedViewController.view.tag;

}


今作っている奴はtitle使う方を採用している。StoryBoard使用。 tagつかうほうがわかりやすいとは思うんだけど。

0 件のコメント:

コメントを投稿