Why am I getting these errors when I try to add a UIWebView to this ViewController header file?

I performed the following steps: http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/

Below are the steps that lead to turning a web application into a native application:

  • Open Xcode.
  • Create a new iPhone project based on the "View-based Application".
  • Move the files for your web application to the Resources folder in Xcode, but cut the cache manifest. (You don’t want the manifest to spin things up, since now everything is local.)
  • Create a new instance variable, webView, inside @interface ViewController header file: IBOutlet UIWebView * webView; // IBOutlet means that it is visible to Interface Builder.
  • and create the property: @property (non-atomic, save) UIWebView * WebView;

Here is what I still have (ViewController.h):

#import <UIKit/UIKit.h> @interface ViewController : UIViewController IBOutlet UIWebView* webView; @property (nonatomic, retain) UIWebView *webView; @end 

However, in step 4, I get two errors in the ViewController header file:

enter image description here

"cannot declare a variable inside @interface or @protocol"

and

"the iboutlet attribute can only be applied to instance variables or properties"

So what am I doing wrong, or is this the wrong guide for the website?

Note. I downloaded the sample project that he had for the iPhone and it worked, but I am following the tutorial so that I can make the version for iPad.

I am in Xcode 4 and the error shows whether iOS 5 or iOS 4.3 really makes any difference.

+4
source share
2 answers

You are missing a pair of curly braces:

 #import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIWebView *webView; } @property (nonatomic, retain) IBOutlet UIWebView *webView; @end 
+6
source

I think you forgot the brackets; try changing your code to

 #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIWebView* webView; } @property (nonatomic, retain) UIWebView *webView; @end 
+2
source

All Articles