iOS 5を使用していますか?
もしそうなら、あなたが見ている問題はここに文書化された変更によるものです:http: //developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/ instp / UIViewController / parentViewController
そのリンクの重要な部分はこれです:
iOS 5.0より前では、ビューに親View Controllerがなく、モーダルで表示されていた場合、それを表示していたViewControllerが返されていました。これはもはや当てはまりません。presentingViewControllerプロパティを使用して、presentingviewコントローラーを取得できます。
したがって、self.presentingViewControllerに変更すると問題が解決する場合がありますが、おそらく解決しないでしょう。
最初のモーダルからこのコードを使用する:
[self dismissModalViewControllerAnimated:YES];
SecondViewController *sec = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
sec.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.presentingViewController presentModalViewController:sec animated:YES];
新しいViewControllerが表示されていません。
新しい(iOS5以降の)方法を使用したい後に自分が何であるかを取得するには:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
このメソッドは、presentModalViewControllerの推奨される代替手段です。
そして、最初のViewControllerのカスタムメソッドは次のようになります。
- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController
この方法では、現在のモーダルを却下することも、新しいモーダルを提示することもできます。たとえば、次のようになります。
- (void)cycleModalViewControllersWithController:(UIViewController *)newViewController {
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:newViewController animated:YES completion:NULL];
}];
}
完了ブロックを使用して新しいモーダルを起動して、古いモーダルがアニメーション化されるまで待ちましょう。したがって、2番目のモーダルビューコントローラーでは、最初のモーダルビューコントローラーでカスタムメソッドを呼び出し、新しいモーダルビューコントローラーの却下/表示を管理できるようにします。