iPhone utility application, Label text does not update in FLipSideView

时间秒杀一切 提交于 2020-01-06 08:27:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!