I’m coding an iPhone app.
Instead of writing all the code here, this is basicly what I want to do:
testViewController.m:
- (void)viewDidLoad { label.text=@"text"; }
This works.
Now I want to change the label text from the testAppDelegate file.
- (void)applicationDidBecomeActive:(UIApplication *)application {
testViewController *tvc=[[testViewController alloc] init];
tvc.label.text=@"another text";
[tvc release];
}
This isn’t working!
How can I do this?
Thanks for all answers 🙂
In applicationDidBecomeActive you are creating a new instance of the view controller (this is what alloc / init) setting the label text in your new instance and then releasing it.
You need to be referring to the actual instance of your view controller that is on the screen. This is probably already referred to somewhere in your application delegate – is it the root view controller, for example? When is it created in the first place?
You may need to set a property on your application delegate to hold a reference to this view controller. The code you have is fine except that you are talking to a new controller instead of the one that is presented on the screen – assuming of course that your label is a property on the view controller.