2011-09-19 24 views
0

我是新來的Objective-C,目前正在按照本書中的教程向我展示如何將新視圖和視圖控制器添加到現有窗口。當我嘗試添加一個新的視圖控制器時,Xcode給了我一個錯誤

這本書在這一點告訴我:

"Add a TestViewController instance to your code and label it as an IBOutlet. We are putting it in the app delegate class, TestAppDelegate. In TestAppDeligate.h the new code will look like this:

IBOutlet TestViewController* testViewController; "

所以,當我改變我的應用程序委託頭文件包含此行代碼它看起來像這樣。

#import <UIKit/UIKit.h> 
#import "TestViewController.h" 

@class views_and_controllersViewController; 

@interface views_and_controllersAppDelegate : NSObject 
<UIApplicationDelegate> { 

} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 

@property (nonatomic, retain) IBOutlet 
views_and_controllersViewController *viewController; 

IBOutlet TestViewController* testViewController; 

@end 

但是在這一點上的Xcode拋出我的錯誤:

Cannot declare variable inside @interface or @protocol

以及警告:

iboutlet attribute can only be applied to instance variables or properties

我沒有失敗注意到,所有其他實例聲明中頭文件的前綴是@property標籤。這是必需的嗎?如果是這樣的話,那麼這本書就會忽略這一點,並期望我已經知道Obj-C期待這樣?

Anywho,我在這裏做錯了什麼?

回答

1

您的IBOutlet TestViewController * testViewController需要在@interface部分中向上移動。

+0

謝謝。像魅力一樣工作。 –

相關問題