Why am I getting these errors when trying to add a UIWebView to this ViewController header file?
I was following the steps here: http://mat开发者_StackOverflowt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/
Here are the bare bones steps to turning a web app into a native app:
- Open XCode.
- Create a new "View-based Application" iPhone project.
- Move the files for your web app into the Resources folder in XCode, but strip out the cache manifest. (You don't want the manifest screwing things up, since everything is now local.)
- Create a new instance variable, webView, inside the @interface ViewController header file: IBOutlet UIWebView* webView ; // IBOutlet means it's visible to Interface Builder.
- and create a property: @property (nonatomic, retain) UIWebView *webView;
Here is what I have thus far (ViewController.h):
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
IBOutlet UIWebView* webView;
@property (nonatomic, retain) UIWebView *webView;
@end
However on step 4 I am getting two errors in my ViewController header file:
"cannot declare variable inside @interface or @protocol"
and
"iboutlet attribute can only be applied to instance variables or properties"
So what am I doing wrong, or is that website tutorial wrong?
Note: I downloaded the sample project he had for iPhone and it worked, but I am following the tutorial so I can make an iPad version.
I am in XCode 4 and the error shows whether I do iOS 5 or iOS 4.3 doesn't seem to make a difference.
You're missing a couple of curly braces there:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
UIWebView *webView;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@end
I think you forgot the brackets; try to change your code to
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UIWebView* webView;
}
@property (nonatomic, retain) UIWebView *webView;
@end
精彩评论