xcode 如何将 WebView 插入可可应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2948932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:24:22  来源:igfitidea点击:

How to insert a WebView into a cocoa app?

cocoaxcodeinterfacewebkitbuilder

提问by spamoom

I'm rather new with the whole OSX programming, I wanted to stick a WebView into an empty app. Apparently it isn't as simple as sticking a WebView on a window in interface builder and creating an outlet.

我对整个 OSX 编程还很陌生,我想将 WebView 粘贴到一个空的应用程序中。显然,它不像在界面构建器的窗口上粘贴 WebView 并创建一个插座那么简单。

IBOutlet WebView *webView;

It gives me a

它给了我一个

expected specifier-qualifier-list before 'WebView'

and when I don't use an outlet, it terminates due to uncaught exception. I'm not too sure what these error messages mean.

当我不使用插座时,它会因未捕获的异常而终止。我不太确定这些错误消息是什么意思。

Seems it isn't that simple!

好像没那么简单!

回答by Georg Fritzsche

You also need to add the WebKit framework to your target and forward declare WebViewor import the header file:

您还需要将 WebKit 框架添加到您的目标并转发声明WebView或导入头文件:

// header file:
@class WebView; // forward declaration sufficient in header
@interface WhatEver ... {
    WebView* webview;
// ...
@property (assign) IBOutlet WebView *webview;
@end

// implementation file:
#import <WebKit/WebView.h> // if you want to do something with the WebView
@implementation WhatEver
@synthesize webview;
// ...
@end

回答by gabr10

Did you try to link the WebKit framework, then importing it?

您是否尝试链接 WebKit 框架,然后导入它?

#import "WebKit/WebKit.h"