I\'m trying to make a simple app with a button a score counter and a timer but I\'m getting some errors
#import
@interface xyzViewCont
You are mixing up interface
and implementation
. The interface contains
the (globally visible) instance variables, properties and method declarations, i.e.
the prototypes:
@interface xyzViewController : UIViewController
{
IBOutlet UILabel *scoreLabel;
IBOutlet UILabel *timerLabel;
NSInteger count;
NSInteger seconds;
NSTimer *timer;
}
- (IBAction)buttonPressed;
@end
The method itself goes into the implementation:
@implementation xyzViewController
- (IBAction)buttonPressed
{
count++;
scoreLabel.text = [NSString stringWithFormat:@"Score \n %i", count];
}
@end
Remarks:
XyzViewController
.Create properties for the outlets (if you don't have them already):
@property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
The compiler synthesizes the instance variable _scoreLabel
automatically, so you don't need it in the interface. And then access the property via
self.scoreLabel.text = ....;