期待";" 在"{"之前?

Ali*_*ons 2 cocoa objective-c

我仍在使用Apple的网站上的WebKit教程遇到问题:http: //developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/MultipleWindows.html

.h文件如下:

#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface MyDocument : NSDocument
{
IBOutlet id webView;
IBOutlet id textField;
}

- (IBAction)connectURL:(id)sender //Provides me with the error 'Expected ";" before "{" token'
{
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[sender stringValue]]]];
}

@end
Run Code Online (Sandbox Code Playgroud)

你能看到任何有问题的东西吗?为什么它会给我一个问题呢?

- 谢谢!

Sam*_*hie 17

是! 你已经在头文件中实现了它.将其移动到.m文件:

- (IBAction)connectURL:(id)sender {
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[sender stringValue]]]];
}
Run Code Online (Sandbox Code Playgroud)

并用方法声明替换它:

- (IBAction)connectURL:(id)sender;
Run Code Online (Sandbox Code Playgroud)


D.C*_*.C. 5

这是一个接口声明,因此您无法在那里实际定义方法.

您只需要在那里声明方法,然后将定义放在一个@implementation块中.