2014-10-04 67 views
-1

我總是得到這個錯誤在代碼的各個單獨的項目,我只是無法弄清楚錯誤是什麼。我使用Xcode 6和Objective C語言。錯誤是:預期;方法原型錯誤後

預計;方法原型後。

#import "ViewController.h" 

@interface ViewController() 

//the error is on the next line 
-(IBAction)number1:(id)sender{ 
SelectNumber = * 10; 
} 

回答

0

您不能將方法體放在@interface塊中。您只能將它們放在@implementation區塊中。

用於UIViewController子類的Xcode模板在.m文件中同時添加了類擴展名(@interface ViewController() ... @end)和實現塊(@implementation ViewController ... @end)。您意外地在類擴展中定義了您的方法。您需要將其移至實施塊。你應該得到這樣的結果:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

-(IBAction)number1:(id)sender{ 
    SelectNumber *= 10; 
} 

@end 
0

你一個.H和/或.m文件的 「@interface」 一節中定義的原型。

那些應該只是一個以分號結尾的行方法聲明。

您應該將整個函數實現移到「@implementation」部分,這就是您在那裏做的。只需將「@interface」更改爲「@implentation」,您就可以編譯好了。

如果您希望將您的函數暴露給其他類&對象,請將您的方法聲明放在.h文件中。