0

我在 Xcode 4.3 中编码时遇到了一件奇怪的事情。标题中描述了问题的性质。我在另一篇文章中提到了这一点以及故事板连接问题。连接问题似乎至少现在已经消失了。但是价值分配问题仍然存在。所以我把它作为一个新帖子。

-(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)

任何想法?

4

1 回答 1

0

感谢路德维格和米尔斯。我在 viewDidLoad 中添加了一行,问题就解决了。但是 NSLog 结果很有趣。

我在代码中添加了这个:

- (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这次一定要改变。

于 2012-07-29T22:20:32.693 回答