TabBarApplication のバックアップ差分(No.2) - アールメカブ

アールメカブ


TabBarApplication のバックアップ差分(No.2)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[Programming]]

self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
Tab Bar Application では任意のView を追加することができる.
[[ここ:http://d.hatena.ne.jp/kurusaki/20081204/1228325765]]を参考にした.

#contents

* View の追加.TableView も同様 [#rb3c7a0d]
手順は

- 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 間の移動 [#f9ce4ec0]
さて,今,最初のタブから NewView タブに移動し,何かのタイミングで,最初のタブに戻りたいとする.TabBar アプリでは,各Viewは配列としてアクセスできる.


たとえば IBAciton として指定されたメソッドに以下を追加することで,最初のタブに移動できる.

 self.tabBarController.selectedIndex = 0;

 self.tabBarController.selectedViewController = 
   [self.tabBarController.viewControllers objectAtIndex:0];

ただ,この際,アニメーションを行う方法が分からない
 viewDidAppear:(BOOL)animated
というめっそどがあるのだが,これではなさそうである.と思って検索したら[[次のような情報:http://osdir.com/ml/iPhoneSDKDevelopment/2009-03/msg00217.html]]があった.

>
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.