3687 Views 8 Replies Latest reply: Feb 9, 2009 4:03 PM by RayNewbie
I know. That's why my question was really how to access the property of a variable declared in RootViewController from MainViewController.
In RootController.h it is
@property (nonatomic, retain) IBOutlet UIButton *infoButton;
and in RootController.m it is
It isn't declared at all in MainViewController - but it is visible in my main view.
So I know it isn't declared there and that is the problem. I just don't know how to "reach" it from my MainViewController methods. That's why I wondered if there was some extra syntax I could use to "reach beyond my current scope" or something.
Or do I have to doubly declare it maybe?
Anyone have any thoughts on this?
I am having the same difficulty.
If you create a project using the Utility template, 3 ViewControllers are created; root, main and flipside.
The RootViewContoller creates a UIButton called infoButton on the MainWindow.xib file. This button is used to toggle between the 2 sub views, MainView and FlipsideView. Each sub view has a viewController.
Is there a way to hide the info button programmatically from a subview viewController? In this case, MainViewController.
self.view.superview.infoButton.hidden = YES;
With no luck.
Hi Doug and Bill. I think Rick Maddy was trying to lead you to the solution instead of finishing his code for you, but I know how frustrating it is to just not see it.. Been there!!!
Here's a snippet from my MainViewController.m where I'm doing something similar with the Utility template:
nState = iState;
MyProgAppDelegate *delegate = [UIApplication sharedApplication].delegate;
RootViewController *rootViewController = delegate.rootViewController;
rootViewController.buMyControl.enabled = nState == 1 ? YES : NO;
Or, if you're doing lots of this you might consider declaring a RootViewController* instance variable (and matching property with retain) in MainViewController.h. You could then initialize that in RootViewController.m viewDidLoad:
MainViewController *viewController = [[MainViewController alloc] initWithNibName:@"MainView" bundle:nil];
viewController.rootViewController = self; // <--- here
self.mainViewController = viewController;
I think kiichi's solution will work too, but note that it depends on keeping the target control at index 1. That might break if you later add other controls to the root view as I did.