Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Xcode中将值从A分配到B_Xcode_Variable Assignment - Fatal编程技术网

无法在Xcode中将值从A分配到B

无法在Xcode中将值从A分配到B,xcode,variable-assignment,Xcode,Variable Assignment,在使用Xcode 4.3编码时,我遇到了一件奇怪的事情。标题中描述了问题的性质。我在中提到了这一点以及故事板连接问题。连接问题似乎至少在目前消失了。但价值分配问题依然存在。所以我把它作为一个新的职位 -(void) setQuestion:(NSString *)question { _question = question; self.questionLabel.text = question; NSLog(@"The quesion i

在使用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)

有什么想法吗

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

我在代码中添加了以下内容:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.questionLabel.text = self.question;
    ...
}
我贴上了
NSLog(@“标签是%@”,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
这次确实会更改。

questionLabel是否已初始化?在Cocoa中,您可以在未初始化的对象上执行此操作,而不会发生崩溃(取决于编译器设置)。在调试器运行时检查其输出,因为您确实会收到警告。我的想法与上面相同。您可以使用
NSLog(@“标签为%@”,self.questionLabel)进行验证