ViewController UIwebview问题

时间:2016-05-29 07:13:29

标签: ios objective-c iphone xcode uiwebview

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

查看控制器标题

@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开头的第一行

1 个答案:

答案 0 :(得分:0)

实例变量缺少{}

@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下面以保持一致性,并且跳过也可以

(在Xcode 4.4之后,编译器将为你生成,但知道原始代码很好)

更多关于课程: https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/ClassMethod.html