ViewController UIwebview 问题

ViewController UIwebview issue

我是 xcode 的新手,所以我正在学习关于将网页放入 xcode 7 中的 ios objective-c 项目的教程。下面是我的代码利用。 @interface ViewController ()

查看控制器header

@interface ViewController : UIViewController

IBOutlet UIWebView* webView;

@property (nonatomic, retain) UIWebView *webView;

@end

view controller main
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@synthesize webView;

@end

错误警告是;

1.Cannot 在@interface 或@protocol 中声明变量'

2.Attribute只能应用于实例变量或属性

并且都适用于以 IBOutlet 开头的第一行

对于实例变量只是缺少{}

@interface ViewController : UIViewController
{
  IBOutlet UIWebView* webView;
}
@property (nonatomic, retain) UIWebView *webView;

@end

但实际上可以跳过声明 例如

@interface ViewController : UIViewController

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

@end

这一行

@synthesize webView;

为了一致性应该放在@implementation下面,也可以跳过

(Xcode4.4后编译器会为你生成,不过知道原代码就好了)

关于 class 的更多信息: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ClassMethod.html