Xcode gives me an error when I try to add a new view controller
I'm new to Objective-C and am currently following a tutorial in a book that is showing me how to add a new view and view controller to an existing window.
开发者_StackOverflow社区The book at this point tells me:
"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;
"
So when I alter my app delegate header-file to include this line of code it looks like this.
#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
However at this point Xcode throws me the error:
Cannot declare variable inside @interface or @protocol
as well as the warning:
iboutlet attribute can only be applied to instance variables or properties
I haven't failed to notice that all other instance declarations in the header file are prefixed with the @property tag. Is this required? And if so has the book simply omitted this with the expectation that I already knew that Obj-C expects this?
Anywho, what am I doing wrong here?
Your IBOutlet TestViewController *testViewController needs to be moved up inside the @interface section.
精彩评论