的Objective-C简单的错误代码“(”
问题描述:
@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请帮忙
谢谢提前
答
你正在工作在头文件(.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;
}