2014-09-10 103 views
-2
@interface ViewController() 

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

-(IBaction)rollButtonClicked:(id)sender 

{ 
    int roll = [self.model getDiceRoll]; 
    int roll2 = [self.model getDiceRoll]; 

    [self.firstDieView showDie:roll]; 
    [self.secondDieView showDieroll2]; 

    NSString *sumText = [NSString stringWithFromat:@"Sum is %d", roll + roll2]; 

    self.sumLabel.text = sumText; 

} 

我不斷收到錯誤,如果我後放置一個分號 - (IBAction爲)rollButtonClicked:(ID)發送者,我會得到「(」如果我刪除它的Xcode會告訴我的問題,因爲它說我需要一個分號後 - (IBAction爲)rollButtonClicked:(ID)發送的Objective-C簡單的錯誤代碼「(」

,你可以看到我還是很新的對象-C請幫忙

謝謝提前

回答

0

你正在工作在頭文件(.h)。
在那裏,你只能聲明函數像這樣:

- (IBaction)rollButtonClicked:(id)sender; 

在您的實現文件(.m)添加您的代碼:

- (IBaction)rollButtonClicked:(id)sender { 
    int roll = [self.model getDiceRoll]; 
    int roll2 = [self.model getDiceRoll]; 

    [self.firstDieView showDie:roll]; 
    [self.secondDieView showDieroll2]; 

    NSString *sumText = [NSString stringWithFromat:@"Sum is %d", roll + roll2]; 

    self.sumLabel.text = sumText; 
}