I have a pointer to a UIView. How do I access its UIViewController? [self superview] is another UIView, but not the UIViewController, right?
I have a pointer to a UIView . How do I access its UIViewController
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, the
superviewis 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.