函数"..."的隐式声明在C99中无效?

Rou*_*vis 4 objective-c function-calls

我试图在另一个函数中声明一个函数.所以这是我的代码的一部分:ViewController.m

- (void)updatedisplay{
    [_displayText setText:[NSString stringWithFormat:@"%d", counter]];

}

- (IBAction)minus1:(id)sender {
    counter--;
    updatedisplay();
}
Run Code Online (Sandbox Code Playgroud)

ViewController.h

- (IBAction)minus1:(id)sender;
- (void)updatedisplay;
Run Code Online (Sandbox Code Playgroud)

其中返回了"隐式声明功能"的错误......"在C99中无效".

结果:http://i.imgur.com/rsIt6r2.png

我发现人们遇到了类似的问题,但作为一个新手,我真的不知道接下来该做什么.谢谢你的帮助!:)

函数'...'的隐式声明在C99上无效

lud*_*ign 11

你没有宣布一个function; 但是instance method,所以要称之为必须将其作为消息发送给self;

[self updatedisplay];

编辑

正如@rmaddy指出的那样(感谢),它被声明为实例方法而不是类方法.使事情清楚;

- (return_type)instance_method_name....通过'self'或指向对象实例的指针调用.
+ (return_type)class_method_name....直接在类上调用(静态).


Lit*_*T.V 5

问题

updatedisplay();
Run Code Online (Sandbox Code Playgroud)

[self updatedisplay];
Run Code Online (Sandbox Code Playgroud)

原因

- (void)updatedisplay;
Run Code Online (Sandbox Code Playgroud)

是一个可用于该类的类方法.因此,您必须从类中调用以使该方法可用.