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

C++ Xcode如何在函数中使用IBOutlet进行标记,c++,objective-c,macos,cocoa,function,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:5

我已连接到我的标签:

@property (weak) IBOutlet NSTextField *scoreBox;
正确,我正试图这样访问它:

void namedfunction(button) {

    if (button == button) {
        score = score + 100;
        [scoreBox setIntValue:score];
      // ^ error
    }
}
我得到一个错误:

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

我做错了什么?

使用

[_scoreBox setIntValue:score];

*还要检查是否以比较相同的按钮结束,如:
button==button

编辑2:

因为您的代码是:

int perus(int nappi){

}
将其更改为:

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

我不确定以下是什么,因为我发现了这个

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

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

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

@user2225385:显示AppDelegate.m和AppDelegate.hy的完整代码如果你有C函数,为什么不切换到obj-C方法?
void namedfunction(const void *button, const void *appDele){
    NSTextField *myButton=[appDele scoreBox];
    ....
}