mahboudz mahboudz - 10 months ago 32
iOS Question

Given a view, how do I get its viewController?

I have a pointer to a

. How do I access its
[self superview]
is another
, but not the
, right?


Yes, the superview is the view that contains your view. Your view shouldn't know which exactly is its view controller, because that would break MVC principles.

The controller, on the other hand, knows which view it's responsible for (self.view = myView), and usually, this view delegates methods/events for handling to the controller.

Typically, instead of a pointer to your view, you should have a pointer to your controller, which in turn can either execute some controlling logic, or pass something to its view.