objective-c - 为什么在尝试将 UIWebView 添加到此 ViewController 头文件时会出现这些错误?

标签 objective-c ipad uiwebview

我按照这里的步骤操作:http://matt.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:

  1. Open XCode.
  2. Create a new "View-based Application" iPhone project.
  3. 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.)
  4. Create a new instance variable, webView, inside the @interface ViewController header file: IBOutlet UIWebView* webView ; // IBOutlet means it's visible to Interface Builder.
  5. and create a property: @property (nonatomic, retain) UIWebView *webView;

这是我目前所拥有的(ViewController.h):

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

    IBOutlet UIWebView* webView;

@property (nonatomic, retain) UIWebView *webView;
@end

但是在第 4 步,我的 ViewController 头文件中出现了两个错误:

enter image description here

"cannot declare variable inside @interface or @protocol"

and

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

那么我哪里做错了,还是那个网站教程错了?

注意:我下载了他为 iPhone 准备的示例项目并且它有效,但我正在按照教程进行操作,以便制作 iPad 版本。

我在 XCode 4 中,错误显示我使用的是 iOS 5 还是 iOS 4.3 似乎没有什么区别。

最佳答案

你少了几个花括号:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    UIWebView *webView;
}

@property (nonatomic, retain) IBOutlet UIWebView *webView;

@end

关于objective-c - 为什么在尝试将 UIWebView 添加到此 ViewController 头文件时会出现这些错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7599221/

相关文章:

ios - 在 uiwebviews 中滚动时空白

ios - UIWebview 在当前文本字段上设置文本

ios - NSURLProtocol + UIWebView + 某些域 = app UI frozen

iOS - NSXMLParser 和 libxml2 的区别

iphone - iOS:如何在设置更改时隐藏 UITextField?

iphone - 为什么我似乎无法在 iPhone 应用程序中取消归档由 OS X 应用程序归档的对象?

c - Objective-C 2.0 垃圾收集是否收集 C 结构?

ios - 将 SubView 添加到窗口关闭 ipad 中的应用程序

ios - 核心数据 : error: Exception was caught during Core Data change processing

objective-c - Xcode 4.2- 在分离的 Nib 文件中存储 View