I have added a subview in my MainViewController. How can i call a method of my MainViewController from my subview?
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.
As part of general code-decopeling strategies of MVC, the view should not know about the controller. (Google is your friend if you don’t know about MVC, it’s important.) If you want interactions with the view to be passed to the controller, you should make a delegate protocol, create a delegate interface, implement it in the controller, and connect the controller to the view’s delegate in interface builder. That probably sounds like a lot, so here’s an example:
Lets say we have a CalendarView, and we want to tell the controller when someone tapped a date, and ask if we should make that the selected date:
1) Make a delegate protocol
2) Add a (non-retained!) delegate property to CalendarView, as an IBOutlet
3) Implement CalendarViewDelegate in whichever controller(s) you need to
MainViewController.h:
MainViewController.m: