I have this object of NSObject class. This object is shown on a view managed by a viewController. How do I get a reference to that viewController from inside the object’s class?
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.
There is no “myViewController” property as you know. The easiest way to give any object access to some other object is through a delegate relationship.
Define a protocol for the delegate – typically in the module that wants access to the object which will be the delegate, i.e. the view controller
Advertise the delegate support in the class implementing it
Implement the function you defined as being part of the protocol in the view controller:
Make a variable in the calling object to store the delegate object
Initialize that object
In myObject – use the defined protocol to access methods in the delegate object!