So, I am following this Xcode tutorial book: Iphone and Ipad Game Development for Dummies. Its a good book, but there are some flaws here and there. Most of the time I can figure a way around these flaws, but now I stumbled upon something I cant fix. Even their website or contacts dont know the answer.
Im trying to make a game with cars and stuff. But the problem lies with the main menu. I already made buttons with custom button mode. And used IbActions to make them work(actually, "New Game" is the only button that works now cause it has its function already scripted). But now I have to make IBOutlets to give them an Animation. The book told me to use the QuartzCore.framework. Now the problem is that when I try to build it I get this error: No Declaration of property 'newGameButton' found in the Interface.
This is my script.
The header file:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface MainMenuViewController : UIViewController {
//This has changed
@property(nonatomic,retain) IBOutlet UIButton* newGameButton; 开发者_运维技巧
@property(nonatomic,retain) IBOutlet UIButton* statsButton;
@property(nonatomic,retain) IBOutlet UIButton* settingsButton;
CAKeyframeAnimation* popAnimation;
}
-(IBAction) newGame:(id)sender;
-(IBAction) showStats:(id)sender;
-(IBAction) showSettings:(id)sender;
@end
And the .m file (its called implantation right?):
#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;
-(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
Now I first tought that they werent connected to the buttons in the User Interface builder. But that didnt work either. I tried to remake the whole script. I tried to reload the script in Xcode. I even tried to make my own version. Im dont have any options left. Does anyone know what is wrong with my script?
set the property of the objects in header file as
@property(nonatomic, retain) IBOutlet UIButton* newGameButton;
.
.
.
and in .m file synthesis them using
@synthesis newGameButton;
do this for all the objects that you have declared
and then connect them in the IB
Are you loading the proper UIViewController?? i mean, if you are working with the interface builder check out that in your main window xib, the viewController object you are using corresponds with your MainMenuViewController class
You have said you were seeing:
"No Declaration of property 'newGameButton' found in the Interface"
Any property that is declared in either the .h (header) or .m (implementation) must be synthesised:
@property (nonatomic,retain) IBOutlet UIButton* newGameButton;
Like this for your properties in the .m (implementation)
@synthesize newGameButton;
精彩评论