no declaration of property 'newGameButton' found in the interface
I tried to find an answer on the internet (this site too), but i cant find the correct answer.
Im trying to give a button an animation, so I used the QuartzCore Framework. But every time I want to play-test it, it gives me this annoying massage: no declaration of property 'newGameButton' found in the interface. I dont know what I did wrong or what I have to do now.
Here is my .h and .m file:
.h file:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface MainMenuViewController : UIViewController {
IBOutlet UIButton* newGameButton;
开发者_开发技巧 IBOutlet UIButton* statsButton;
IBOutlet UIButton* settingsButton;
CAKeyframeAnimation* popAnimation;
}
-(IBAction) newGame:(id)sender;
-(IBAction) showStats:(id)sender;
-(IBAction) showSettings:(id)sender;
@end
.m file:
#import "MainMenuViewController.h"
#import "TrafficAppDelegate.h"
#import "TrafficViewController.h"
@implementation MainMenuViewController
-(IBAction) newGame:(id)sender{
TrafficViewController* traffic = [[TrafficViewController alloc] initWithNibName:@"TrafficViewController" bundle:nil];
[self.navigationController pushViewController:traffic animated:NO];
}
-(IBAction) showStats:(id)sender{
}
-(IBAction) showSettings:(id)sender{
}
@synthesize newGameButton, statsButton, settingsButton; (This is the error causer!)
-(void)viewDidLoad{
[super viewDidLoad];
popAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
popAnimation.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.7], [NSNumber numberWithFloat:1.0], nil];
popAnimation.values = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.01], [NSNumber numberWithFloat:1.1], [NSNumber numberWithFloat:1.0], nil];
[popAnimation retain];
}
-(void)popView:(UIView*)view{
[view setHidden:NO];
[[view layer] addAnimation:popAnimation forKey:@"transform.scale"];
}
-(void)viewWillAppear:(BOOL)animated{
[popAnimation setDuration:0.3];
[newGameButton setHidden:YES];
[statsButton setHidden:YES];
[settingsButton setHidden:YES];
[self performSelector:@selector(popView:) withObject:newGameButton afterDelay:0.25];
[self performSelector:@selector(popView:) withObject:statsButton afterDelay:0.3];
[self performSelector:@selector(popView:) withObject:settingsButton afterDelay:0.35];
}
@end
I am totally clueless, so please help!
The error is self-descriptive - you need to declare properties you synthesize in class interface, e.g.:
@interface MainMenuViewController : UIViewController {
...
}
...
@property (nonatomic, retain) IBOutlet UIButton* settingsButton;
@end
I'd suggest (Re-)reading about properties in Objective-c reference docs
You're trying to access a property that simply does not exist.
Look at your @interface
, do you see any @property
declarations?
This will work:
@interface MainMenuViewController : UIViewController {
IBOutlet UIButton* newGameButton;
IBOutlet UIButton* statsButton;
IBOutlet UIButton* settingsButton;
CAKeyframeAnimation* popAnimation;
}
@property (nonatomic, retain) IBOutlet UIButton *newGameButton, *statsButton, *settingsButton;
精彩评论