I'm trying to update one textfield from another class:
I have two classes:
@interface FlipsideViewController : UIViewController <PostDistanceControllerDelegate> {
id <FlipsideViewControllerDelegate> delegate;
IBOutlet UITextField *currentStatus;
IBOutlet UITextField *currentUpdateDate;
}
@property ...
In my FlipsideViewController.m I can use:
@implementation FlipsideViewController
//....
- (IBAction)done:(id)sender{
currentStatus.text=@"TOTO";
}
Now I have a second class in which I'm trying to update the text from the first class...
@implementation OthersideViewController
-(void)setStatus{
[FlipsideViewController currentStatus.text=@"TEST"};
}
开发者_高级运维I know I can't re-initialize the controller because it's already initialized. I tried to extern the currentStatus field and it doesn't work. I tried using a getter and a setter as your would do in Java and it the debugger says: unrecognized selector
Any idea?
You're trying to set a property of a member by sending a message to the class and that's why it doesn't work. You'll need to have a reference to the instance of FlipViewSideController and call such as:
-(void)setStatus{
[FlipsideViewControllerInstance currentStatus.text=@"TEST"};
}
So either you pass the FlipViewController instance to your setStatus method as a parameter
-(void)setStatusOfViewControllerLabel:(FlipViewController *) FlipsideViewControllerInstance {
[FlipsideViewControllerInstance currentStatus.text=@"TEST"};
}
or you keep a reference to it in your OthersideViewController object.
Edited for clarity.
Assuming you have declared your property and then synthesized it, and you have a "FlipsideViewController *flipside" variable, then you can use
[flipside currentStatus].text = @"TEST";
or
[[flipside currentStatus] setText:@"TEST"];
精彩评论