LoginSignup
7

More than 5 years have passed since last update.

[Objective-C] ViewController間の遷移

Posted at

遷移の仕方一覧

よく頭が混んがらがるのでメモまとめました
いまだ何がベストかちょっとわかってないですが・・・;

以下を考慮して臨機応変に
・コードでの遷移
・StoryBoardのsegueを使った遷移
・NavigationControllerを使った遷移

Present

[self presentViewController:移動先ViewController animated:YES completion:nil];

segue

[self performSegueWithIdentifier:@"セグエのID" sender:self];

Push

[self.navigationController pushViewController:移動先ViewController animated:YES];

Pop

指定ビューコントローラーへ

[self.navigationController popToViewController:viewController animated:YES];

前の画面に戻る

[self.navigationController popViewControllerAnimated:YES];

NavigationControllerの1番目の画面に戻る

[self.navigationController popToRootViewControllerAnimated:YES];

StoryBoard

・StoryBoard ID

※storyboardファイルで 'identify → StoryBoard ID'の入力が必要

UIStoryBoard* storyBoard = [UIStoryboard storyboardWithName:@"ストーリボードID" bundle:nil];
UIViewController* viewController = [storyboard instantiateInitialViewController];

・StoryBoard initial ViewController

※storyboardファイルで 'is initial View Controller'のチェックが必要

UINavigationController* rootNavigationController = [storyboard instantiateInitialViewController];
UIViewController* viewController = [[rootNavigationController viewControllers] lastObject];

そのうち
Swiftのメモもまとめたいです

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7