将self用于局部变量

时间:2015-01-22 03:25:35

标签: objective-c xcode6

我正在学习Objective-C,这本书是关于一本三四年前的书(称为Tap,Move,Shake)。 我遇到的问题是书中的一个例子,他们解释了如何创建标签和按钮,然后他们在.h文件中创建了插座,如下所示:

@property (weak, nonatomic) IBOutlet UILabel *label;

然后他们只在函数中使用.m文件中的变量标签,如下所示:

- (void)generate
{
// pick two numbers between 1 and 9
int a = 1 + arc4random() % 9;
int b = 1 + arc4random() % 9;

// calculate the sum
int sum = a + b;

// create one question
label.text = [NSString stringWithFormat: @"%d + %d", a, b];

// save the answer in the tag property of the label
label.tag = sum;
}

但是XCode给了我这个错误:"必须使用struct来引用类型'标签'。"

根据我的理解,变量已经在.h中定义为局部变量,所以我应该能够从.m中检索,对吧? (或者至少这是我从书中的例子中理解的)。

我已设法通过更换标签来解决这个问题'由自我标签' - 这使它现在工作正常。

如果有人可以向我提供更多相关信息,我将非常感激。

提前多多感谢!

0 个答案:

没有答案