[iOS SDK] モーダル表示したViewController を取得する

UIViewControllerの presentViewController:animated:completion: で UINavigationController を表示して、そのUINavigationController に pushViewController させようとしたところモーダル表示中の UINavigationController を取得する方法がなかなか見つけられなかったのでメモ。

iphone – IOS Accessing a Modal View in AppDelegate – Stack Overflow

にあるとおり、

self.window.rootViewController.presentedViewController

で取得できる。

名前がまぎらわしいけれども下記の関係がある。

  • presentedViewController : 前面に表示された ViewController
  • presentingViewController : presentedViewController を表示したViewController

前面に表示されていないときには、presentedViewController は nil になっているようだ。

逆に、背面にある UIViewController を操作したい場合は
ModalViewの後ろ側にあるViewControllerを操作する方法 | ssdkfk

を参照のこと。

返信を残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.