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

时间:2013-11-29 01:53:18

标签: objective-c xcode macos webkit

我在WebView中打开URL时遇到问题。有一段时间没有使用objective-c进行编程,看起来我编码的内容已经贬值了。应用程序打开,加载URL但崩溃时出现此错误

  

线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x20)

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

以下是代码:

AppDelegate.h

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

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

@property

(retain, nonatomic) IBOutlet WebView *myWebView;


@end

AppDelegate.m

#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属性'myWebView'将使用合成实例   变量'_myWebView',而不是现有的实例变量'myWebView'

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

删除你的大括号WebView *myWebView;的声明,这是不必要的。