I have a single view application. It has myAppDelegate and myViewController. In a earlier learning project I did from a book, myViewController.h contained the following:
IBOutlet UILabel *textField;
And to display text to that label on the iPhone, it had you put the following in myViewController.m:
[textField setText:@"Hello World!"];
And it worked! Pretty! But…how do I accomplish the same from myAppDelegate? If I put that same line above inside myAppDelegate.m, inside:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
I get an error: Use of undeclared identifier ‘textField’.
So I can I print text to that same label inside myViewController from myAppDelegate?
Thanks!!
The best answer would probably be, “Don’t…because the view controller should be responsible for its own views.”
However, practically, you need to have a reference to your view controller in order to change one of its properties. The syntax would be something of the form
[controller.textField setText:@"Hello World!"];, but with your own variable name as the target. The exact statement would depend on what’s currently in yourdidFinishLaunchingWithOptions:method and how your app delegate and view controller are connected to each other.