You need to create a delegate variable in your AnotherViewController, and when you initialize it from the RootViewController, set the instance of RootViewController as the delegate of AnotherViewController.
To do this, add the instance variable to AnotherViewController: "id delegate;". Then add two methods to AnotherViewController:
- (id)delegate { return delegate; } - (void)setDelegate:(id)newDelegate { delegate = newDelegate; }
Finally, in the RootViewController, where AnotherViewController is initialized, do
[anotherViewControllerInstance setDelegate:self]
Then when you want to execute toggleView do
[delegate toggleView]
Alternatively, you can make your RootViewController a single, but the delegation method is definitely better. I also want to note that the method I was telling you about was Objective-C 1.0. Objective-C 2.0 has some new features, however, when I studied Obj-C, it was very confusing for me. I would like to get 1.0 down before looking at the properties (this way you will understand what they do in the first place, they basically just automatically create getters and setters).
source share