问题
I am using the utility application template in Xcode with a main and a flipside view. In the main view I have a property label called L0. I am trying to copy that label on the flipside view. On the flipside view, I have declared
@property (weak, nonatomic) IBOutlet UILabel *label;
It is synthesized in the .m file
@synthesize label = _label;
and my prepareForFegue method is :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
FlipsideViewController *fsv = (FlipsideViewController *)[segue destinationViewController];
fsv.label = self.L0;
fsv.delegate = self;
}}
However the text of the label on the flipsideview doesn't change although if I NSLog fsv.label.text in prepareForSegue I see that it is properly set to the value of L0.text.
Any Idea on what am I doing wrong?
回答1:
At the point of prepareForSegue your destination view controller has been created, but the view hasn't loaded. Therefore whatever you assign to the label is overwritten when the view is loaded. You can confirm this by logging the label property before you do anything with it - it will be nil.
The destination VC should have a string property instead, which you set in prepareForSegue with your desired text. You then set the label's text from this string property in viewWillAppear.
来源:https://stackoverflow.com/questions/10370133/iphone-utility-application-label-text-does-not-update-in-flipsideview