paranitips

Never stop learning! がモットーのゆるふわエンジニアブログ

ViewControllerがpresentされたのかpushされたのか判定する

ViewControllerがモーダルされたのかプッシュされたのか判定したい場合がしばしばあります。(例えば、モーダルのときは「閉じる」ボタン、プッシュのときは「戻る」ボタンに変更したいときとか。)

if(self.presentingViewController != nil)
{
    // モーダルされたときの処理
}

else
{
   // プッシュされた時の処理
}

判定のタイミングは-(void)viewWillAppear:(BOOL)animatedあたりが妥当ですかね。

参考

iphone - Reusing a View Controller with both push and modal segues - Stack Overflow