无法在 Xcode 中将值从 A 分配给 B [英] Fail to assign value from A to B in Xcode

查看:23
本文介绍了无法在 Xcode 中将值从 A 分配给 B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 4.3 中编码时遇到了一件奇怪的事情.标题中描述了问题的性质.我在 另一篇文章中提到了这个和故事板连接问题.连接问题似乎至少暂时消失了.但是赋值问题依然存在.所以我把它作为一个新的帖子.

I encounter a strange thing while coding in Xcode 4.3. The nature of problem is described in the title. I mentioned this together with a storyboard connection problem in another post. The connection problem seems to go away at least for now. But the value assign problem persists. So I put it up as a new post.

-(void) setQuestion:(NSString *)question
    {
        _question = question;
        self.questionLabel.text = question;
        NSLog(@"The quesion is %@",question);
        NSLog(@"The quesion label text is %@",self.questionLabel.text);
    }

NSLog 的结果:

2012-07-29 04:03:53.817 Kitchen Sink[18628:f803] The quesion is What do you want your label to say? 
2012-07-29 04:03:53.820 Kitchen Sink[18628:f803] The quesion label text is (null)

有什么想法吗?

推荐答案

感谢 Ludvig 和 Mills.我在 viewDidLoad 中添加了一行,问题解决了.但是 NSLog 结果很有趣.

Thanks for Ludvig and Mills. I add a line in viewDidLoad and problem solved. But the NSLog result is interesting.

我在代码中添加:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.questionLabel.text = self.question;
    ...
}

然后我把NSLog(@"The label is %@",self.questionLabel); 显示如下:

2012-07-30 06:08:59.066 Kitchen Sink[21285:f803] The quesion is What do you want your label to say?
2012-07-30 06:08:59.068 Kitchen Sink[21285:f803] The quesion label text is (null)
2012-07-30 06:08:59.069 Kitchen Sink[21285:f803] The label is (null)

为什么标签仍然为空?但是self.questionLabel.text这次确实改变了.

Why the label is still null? But self.questionLabel.text do change this time.

这篇关于无法在 Xcode 中将值从 A 分配给 B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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