关于 xcode:Objective-c: 在 WebView 中打开 URL (Mac)

Objective-c: Open URL in WebView (Mac)

我在 WebView 中打开 URL 时遇到问题。有一段时间没有用objective-c编程了,看起来我正在编码的东西已经贬值了。应用程序打开,加载 URL,但由于此错误而崩溃

Thread 1:EXC_BAD_ACCESS (code=1, address=0x20)

过去我最初使用它来帮助我编程:[如何在 WebView(OSX 项目)中加载 URL 启动?

代码如下:

AppDelegate.h

1
2
3
4
5
6
7
8
9
10
11
12
13
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>

@interface AppDelegate : NSObject <NSApplicationDelegate> {
    WebView *myWebView;
}

@property

(retain, nonatomic) IBOutlet WebView *myWebView;


@end

AppDelegate.m

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#import"AppDelegate.h"
#import <WebKit/WebKit.h>

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSString *urlText = @"http://google.com";
    [[self.myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
    return;
    // Insert code here to initialize your application
}

@end

我在构建之前在 AppDelegate.m 中收到警告

Autosynthesized property 'myWebView' will use synthesized instance
variable '_myWebView', not existing instance variable 'myWebView'

我该如何解决这个问题?


对于您问题的第二部分,即在 webview 中打开 URL,有一个名为 Macgap 的 phoneGap(http://phonegap.com) 分支可用。你可以在这里查看,http://github.com/maccman/macgap


删除大括号内的 WebView *myWebView; 声明,没有必要。