1

View Controller Programming GuideUIViewControllerを読み、インターネットでたくさん検索しましたが、まだ混乱しています。

利用可能なメソッドの数firstVCにジャンプまたは切り替えたい場合は? secondVC私が知っているものをリストしています:

  1. UINavigationController

  2. UITabBarController

  3. presentModalViewController:

  4. ルート ビューに secondVC を追加する

    • secondVC がルート ビューに追加された場合、firstVC オブジェクトはどのように解放されますか?
    • ルートビューにジャンプ/切り替えたいすべてのビューを追加するのは良い習慣ですか?
  5. transitionFromView:

    • Apple docのこの部分がわかりません:

このメソッドは、ビュー階層内のビューのみを変更します。アプリケーションのView Controllerを変更することはありません。たとえば、このメソッドを使用してビュー コントローラーによって表示されるルート ビューを変更する場合、ビュー コントローラーを適切に更新して変更を処理する必要があります。

私がこれを行う場合:

secondViewController *sVc = [[secondViewController alloc]init];

[transitionFromView:self.view toView:sVc.view...

それでもviewDidLoad:viewWillAppear:viewDidAppear:正常に動作しています。呼び出す必要はありません。では、なぜ Apple は次のように言ったのでしょうか。

変更を処理するためにビュー コントローラーを適切に更新するのはユーザーの責任です。

他に利用可能な方法はありますか?

4

1 に答える 1

1

実際に使用される標準的な方法は次のとおりです。

1) NavigationController の使用

 //push the another VC to the stack
[self.navigationController pushViewController:anotherVC animated:YES];

//remove it from the stack
[self.navigationController popViewControllerAnimated:NO];

//or presenting another VC from current navigationController     
[self.navigationController presentViewController:anotherVC animated:YES completion:nil];

//dismiss it
[self.navigationController dismissViewControllerAnimated:YES completion:nil];

2) VCの提示

//presenting another VC from current VC     
[self presentViewController:anotherVC animated:YES completion:nil

//dismiss it
[self dismissViewControllerAnimated:YES completion:nil];

ポイント4で説明した方法は絶対に使用しないでください。ルートビューコントローラーを動的に変更することはお勧めできません。ウィンドウのルート VC は、通常、applicationdidfinishlaunchingwithoptions で定義されます。その後は、Apple の標準に従う場合は変更しないでください。

transitionFromView:toView の例

-(IBAction) anAction:(id) sender {
// assume view1 and view2 are some subviews of self.view
// view1 will be replaced with view2 in the view hierarchy
[UIView transitionFromView:view1 
                    toView:view2 
                  duration:0.5 
                   options:UIViewAnimationOptionTransitionFlipFromLeft   
                completion:^(BOOL finished){
                    /* do something on animation completion */
                  }];
  }

}
于 2013-05-03T12:34:45.853 に答える