I’m using Cocos2D, and I need to access a parent method in a UIView that is added to a UIViewController from another class. My hierarchy goes like this:
Branch 1: window > viewController.view > glView > joinedMapsScene > joinedMapsLayer
Branch 2: window > viewController.view > foregroundLabelView
When my label class used to be part of Cocos2D, accessing was easy by doing something like this:
JoinedMapsScene *joinedMapsScene = (JoinedMapsScene*)self.parent;
[joinedMapsScene.tetraCounter incTetras:-1];
But now I need to call the method in foregroundLabelView from joinedMapsLayer. It may not be so much of a cocos2D question, but I’m just really confused about this sort of stuff still.
If I had understood well you want to retrieve the foregroundLabelView instance from joinedMapsLayer. There is a way but I don’t know if it’s optimal.
You can in your AppDelegate.h instantiate a foregroundLabelView.
Then when you init your foregroundLabelView you assign it to the AppDelegate foregroundLabelView: in your foregroundLabelView.m (you have to import AppDelegate.h), at the end of the init method you can do
Then whenever you want you can retrieve it by doing:
and then access the method:
I think this should work.