I have a Class: myTabController, in this class I have a UITabBarController, which has 4 subviews in this UITabBarController.
Now I am in my first subview, say it’s tab1,
I can call self.parentViewController to get the UITabBarController, and this UITabBarController is owned by myTabController, but How can I get myTabController then? Cause I want to access some data in myTabController.
Thanks Ahead,
Regards
From your wording I am assuming that you have not subclassed UITabBarController. I would suggest having a property on all four view controllers, something like
theTabController, which points to an instance of your class. Declare this property like this (in the subviews):Then, in each subview’s implementation, add a synthesize statement. It’s also a good idea to import the header of
myTabControllerin the.m, even though we have an@classin the subview’s header. I used an@classto prevent circular imports.From
myTabController, you need to set this property on each subview like this:Finally, use the
theTabControllerproperty sub inside each subview withself.theTabController.I also have to point out: it’s never good to have a class name that starts with a lower case letter.
myTabControllershould really beMyTabController.