kade

技術系の記事を書いていきます。

Objective-C: ModalViewの画面遷移

modalViewの扱いについて理解しきっていないのであまり詳しくは書けないのですが、iOS6以降非推奨となっていてWARNINGの出る、modalViewController系の出し入れの新たな記法です。

まず、modalViewの変更

// 今まで(非推奨)
// [self presentModalViewController:testViewController animated:YES];
// これから
[self presentViewController:testViewController animated:YES completion:nil];

次に、modalViewを閉じる

// 今まで(非推奨)
// [self dismissModalViewControllerAnimated:YES];
// これから
[self dismissViewControllerAnimated:YES completion:nil];

ちなみにcompletionというところで、画面遷移が終わった後の処理を記載出来ます。

[self presentViewController:testViewController animated:YES completion:^{NSLog(@"hoge")}];

基本はviewWillAppearやviewDidAppearで処理していれば問題ない気もしますが、何か使えそうです。