There's an echo in my head

日々のメモ。

UINavigationControllerDelegateのnavigationController:willShowViewController:animated:で直前に表示されていたUIViewControlleを参照する

Persistent rightBarButtonItem Property of UINavigationItemに書かれていることがやりたくてUINavigationControllerDelegatenavigationController:willShowViewController:animated:を使おうとしたんだけど、navigationController.visibleViewControllerがすでに新しい表示先であるviewControllerを指してしまってたので直前に表示されていたUIViewControllerを参照できなかった。 ^1

というわけで、push/popの前後のvisibleViewControllerを別途参照できるようにサブクラスを作った。

これを使うとnavigationController.outgoingViewControllerでpush/popされる直前のUIViewControllerを参照できる。その後は破棄されてしまうだろうからnilを代入してるので、UINavigationControllerDelegateの範囲内でしか使えないと思う。

このブログに出てくるコードスニペッツは、引用あるいは断りがない限りMITライセンスです。