TabBarApplication
Tab Bar Application では任意のView を追加することができる. ここを参考にした.
_ View の追加.TableView? も同様
手順は
- View.xib を新規に作成.NewView?.xibとする
- Libraryから View Controller を選択,MainWindow?.xibのTab Bar Controllerの下,Tab Barにドラッグ & ドロップ
- Tab が増えるので,その View をクリック.Inspector の NIB Nameに先に用意した NewView?.xib の名前を設定
- この新しいタブの View 用の UIViewController? クラスファイルを新規作成する.NewViewController?.h と NewViewController?.m とする.
- NewView?.xib を開いて,File's Owner のクラスを今作成した NewViewController? とする.
- File's Owner と View をアウトレット接続する
- View の Inspectorで View Simulated Bar Metrics の Status Bar と Bottom Bar を設定しておく
これで実行できるTableView? でも同じ手続きで追加できる.
_ Tab 間の移動
さて,今,最初のタブから NewView? タブに移動し,何かのタイミングで,最初のタブに戻りたいとする.TabBar? アプリでは,各Viewは配列としてアクセスできる.
たとえば IBAciton として指定されたメソッドに以下を追加することで,最初のタブに移動できる.
self.tabBarController.selectedIndex = 0;
か
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
ただ,この際,アニメーションを行う方法が分からない
viewDidAppear:(BOOL)animated
というメソッドがあって紛らわしい(クラスでオーバーライトを忘れたかもしれない。).
と思って検索したら次のような情報があった.
I'm switching between a view maintained by UITabBarController? & a view maintained by UIViewController?. The switching is done through flip animation -- UIViewTransitionFlip? I think, I'm not on my dev box now. To achieve the view switching in this way you cannot add UITabBarController?.view onto window.view as you normally do.
I think I have finally found a solution to this, neatly. What I did was:
- 2. Create a TabController? : UITabBarController?. Then assign UIViewControllers?/UINavigationControllers? as required.
- 5. Add RootViewController?.view onto window.view
Link: Programming(5276d)
iPhone_Dev(5518d)
Last-modified: 2009-04-13 (月) 08:39:20 (5783d)