Fail to assign value from A to B in Xcode

守給你的承諾、 提交于 2019-12-08 09:45:46

问题


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

The result of the 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)

Any thought?


回答1:


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

I add this in code:

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

And I put up NSLog(@"The label is %@",self.questionLabel); It shows the following:

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)

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



来源:https://stackoverflow.com/questions/11713036/fail-to-assign-value-from-a-to-b-in-xcode

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