Search code examples
iphoneuiviewcontrollerparentviewcontroller

iPhone - Accessing the parent viewcontroller?


I have 2 viewcontrollers A, B

  1. ViewController A is being displayed on the screen
  2. The view of ViewController B is added to the view of ViewController A.

How can i access ViewController A from ViewController B without passing a pointer?

self.parentViewController does not work it returns nuil


Solution

  • This should work though its not very elegant:

    UIViewController* viewControllerA = 
        (UIViewController*) [[self.view superview] nextResponder];