iPhone实用程序应用程序,标签文本不会在FLipSideView中更新 [英] iPhone utility application, Label text does not update in FLipSideView

查看:82
本文介绍了iPhone实用程序应用程序,标签文本不会在FLipSideView中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode中使用实用程序应用程序模板,主视图和翻转视图。
在主视图中,我有一个名为L0的属性标签。我试图在侧面视图上复制该标签。
在另一侧视图中,我已宣布

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;

它在.m文件中合成

@synthesize label = _label;

我的prepareForFegue方法是:

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; 
}}

然而,如果翻译旁边的标签文字不会改变我在prepareForSegue中的NSLog fsv.label.text我看到它被正确设置为L0.text的值。

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?

推荐答案

在prepareForSegue时,您的目标视图控制器已创建,但视图尚未加载。因此,在加载视图 时,将覆盖分配给标签的任何内容。您可以通过在执行任何操作之前记录label属性来确认这一点 - 它将为零。

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.

目标VC应该有一个字符串属性,您可以在prepareForSegue中使用所需的文本进行设置。然后,在viewWillAppear中从此字符串属性设置标签的文本。

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.

这篇关于iPhone实用程序应用程序,标签文本不会在FLipSideView中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆