TabBarApplication - アールメカブ

アールメカブ


TabBarApplication

Programming

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:

  • 1. Create a RootViewController? : UIViewController?
  • 2. Create a TabController? : UITabBarController?. Then assign UIViewControllers?/UINavigationControllers? as required.
  • 3. Create OtherSideView? : UIViewController?.
  • 4. Add TabController?.view onto RootViewController?.view.
    • a. Before adding TabController?.view onto RootViewController?.view set RootViewController?.view.frame with UIScreen.mainScreen.bounds.
    • b. I have to do the above to allow TabController?.view scales & fits nicely otherwise the view will shift down about 20 pixel. I have no idea why.
  • 5. Add RootViewController?.view onto window.view
  • 6. When switching the views or animating the flipping, if you like, before adding the OtherSideView?.view onto RootViewController?.view,
    • do set RootViewController?.view.frame with UIScreen.mainScreen.applicationFrame. This to allow OtherSideView?.view to be fitted and scaled nicely.
 
Link: Programming(4982d) iPhone_Dev(5225d)
Last-modified: 2009-04-13 (月) 08:39:20 (5489d)