Xcode如何在函数中使用时使用IBOutlet进行标记

时间:2013-03-29 18:34:34

标签: c++ objective-c macos cocoa function

我与我的标签有关:

@property (weak) IBOutlet NSTextField *scoreBox;

正确,我正试图像这样访问它:

void namedfunction(button) {

    if (button == button) {
        score = score + 100;
        [scoreBox setIntValue:score];
      // ^ error
    }
}

我收到了这个错误:

  

AppDelegate.m:52:10:使用未声明的标识符'scoreBox'

我做错了什么?

1 个答案:

答案 0 :(得分:5)

使用

[_scoreBox setIntValue:score];

或者

[self.scoreBox setIntValue:score];

* 同时检查您最终是否比较了相同的按钮,如:button==button

编辑2:

您的代码是:

int perus(int nappi){

}

将其更改为:

- (NSInteger *)perus:(NSInteger *)nappi{
    //all should do inside, rest are OK.
}

<击> 编辑:

<击>

我不确定以下内容here

* 我建议您切换到obj-c方法,而不是使用C函数来处理这类事情。

C函数只是一个代码块,没有附加到任何东西 其他。您的实例变量附加到每个Controller对象。 所以当你调用printChatter()时,无法知道哪一个 您要使用的Controller实例。你可以添加一个对象 变量到你的函数:

void namedfunction(const void *button, const void *appDele){
    NSTextField *myButton=[appDele scoreBox];
    ....
}

<击>