LoginSignup
67
65

More than 5 years have passed since last update.

Storyboardを使わずにStoryboardにあるViewControllerに遷移する

Last updated at Posted at 2014-01-07

備忘。

参照元こちら。
http://nw.tsuda.ac.jp/class2013/3proj/changeViewController/changeViewController.html

navigationControllerを使った場合を想定して書いています。

// ストーリーボードを指定する
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
// 遷移先のViewControllerをStoryBoardをもとに作成
HogeViewController *hogeViewController = [storyboard instantiateViewControllerWithIdentifier:@"ここにStoryboardのStoryboard IDに書いた名前を書く"];
// 画面をPUSHで遷移させる
[self.navigationController pushViewController:hogeViewController animated:YES];

TableViewControllerで、セルのアクセサリをタッチしたら、hogeViewControllerに遷移する例

// アクセサリーが押された時に遷移する
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    HogeViewController *hogeViewController = [storyboard instantiateViewControllerWithIdentifier:@"hogeHoge"];
    // プロパティに値(indexPath)も渡しちゃう
    hogeViewController.indexPath = indexPath;
    // Pushで遷移
    [self.navigationController pushViewController:editWineViewController animated:YES];
}
67
65
0

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
67
65