2014-02-09 58 views
0
- (IBAction)buttonPressed { 
    count++; 

    scoreLabel.text = [NSString stringWithFormat:@"Score\n%i", count]; 
} 

关闭初学者ios教程。他使用xcode并且不会收到此错误。我刚收到错误(IBAction)buttonPressed说我需要放入一个;但它没有;当我确实把一个;在它不做任何事情!请帮忙!!Xcode 5错误永远不会消失

+0

请将确切的错误消息添加到您的问题。另外,如何声明'count'以及在哪里? – zaph

+0

错误消息是“预期”;“方法原型后“。 上面声明count。计数声明为 NSInteger count; – user3288834

回答

1

错误是因为该方法在接口中声明,而不是实现。

这里是你想要的东西:

在.h文件

@interface YourClassNameHere : SuperClassNameHere { 
    int count; 
} 
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel; 
@end 

在.m文件

@implementation YourClassNameHere 
- (IBAction)buttonPressed { 
    count++; 
    self.scoreLabel.text = [NSString stringWithFormat:@"Score\n%i", count]; 
} 
@end 

IBOutlet财产scoreLabel需要连接到UILabel

+0

它在ViewController.h中没有实现 – user3288834

+0

方法必须在'@ implementation'而不是'@interface'中,这就是问题所在。该实现应该在.m文件中。 – zaph

+0

发现我必须重新开始一切。感谢误导教程... – user3288834