2011-01-10 47 views
3

因此,我正在關注這個Xcode教程書:Iphone和Ipad Game for Dummies。它是一本好書,但在這裏和那裏存在一些缺陷。大多數時候我都能找到解決這些缺陷的方法,但是現在我偶然發現了一些我無法修復的東西。即使他們的網站或聯繫人也不知道答案。Stuck with IBOutlet文件

我試圖做一個汽車和東西的遊戲。但問題在於主菜單。我已經用自定義按鈕模式製作了按鈕。並使用IbActions使它們工作(實際上,「新遊戲」是現在起作用的唯一按鈕,因爲它的功能已經腳本化)。但現在我必須讓IBOutlets給他們一個動畫。這本書告訴我要使用QuartzCore.framework。現在的問題是,當我嘗試構建它時,我得到這個錯誤:在接口中找不到屬性'newGameButton'的聲明。

這是我的腳本。

頭文件:

#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 

與.m文件(其稱爲植入右):

#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 

現在我第一次因子評分,他們的werent連接到按鈕的用戶界面建設者。但那也沒用。我試圖重寫整個腳本。我試圖在Xcode中重新加載腳本。我甚至試圖製作我自己的版本。我沒有任何選擇。有人知道我的腳本有什麼問題嗎?

回答

3

設置在頭文件中的對象的屬性作爲 @property(nonatomic, retain) IBOutlet UIButton* newGameButton; . . .

和.m文件合成它們使用 @synthesis newGameButton; 對於已經聲明 ,然後他們在IB

連接的所有對象做到這一點
+0

到目前爲止好。沒有更多的錯誤。但是現在當我構建遊戲時,iphone模擬器開始遊戲,顯示主菜單,但沒有按鈕!這些是我的變化:頭文件:@property(nonatomic,retain)IBOutlet UIButton * newGameButton; @property(nonatomic,retain)IBOutlet UIButton * statsButton; @property(nonatomic,retain)IBOutlet UIButton * settingsButton; .M文件沒有更改會導致合成同步。我已將Oultets連接到IB – Amacoder 2011-01-10 12:25:33

1

您是否正在加載正確的UIViewController?我的意思是,如果你與Interface Builder的工作檢查,在主窗口廈門國際銀行,該的viewController對象使用的是對應你的MainMenuViewController類

0

你說你看到的:

"No Declaration of property 'newGameButton' found in the Interface"

任何即無論是在.H(頭)或.M(實現)聲明的屬性必須被合成:

 @property (nonatomic,retain) IBOutlet UIButton* newGameButton; 

像這樣的.M你的屬性(實現)

@synthesize newGameButton;