xcode WebView - 无法在(NSWindow)上设置(contentViewController)用户定义的检查属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29869280/
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
WebView - Failed to set (contentViewController) user defined inspected property on (NSWindow)
提问by Snowcrash
I create a new Xcode project from scratch and it compiles fine.
我从头开始创建一个新的 Xcode 项目,它编译得很好。
I add a label to the View Controller and this compiles / runs / shows fine.
我向视图控制器添加了一个标签,这可以编译/运行/显示正常。
I then drag in a WebView into the View Controller but get this message when I run the application:
然后我将 WebView 拖入视图控制器,但在运行应用程序时收到此消息:
Failed to set (contentViewController) user defined inspected property on (NSWindow): *** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (WebView)
What am I doing wrong?
我究竟做错了什么?
回答by user2589681
Just Link Webkit.framework in general->Linked Framework and Libraries
只需链接 Webkit.framework 一般-> 链接的框架和库
回答by Noah Mayo
Well first of all you need to define the Web view so it actually knows what todo all it is doing right now is trying to find what to run here, see a tutorial on youtube or such, this is the code i used for mine, just to set it up. first you want to put the web view into the view controller and add a toolbar to the bottom of it. add four bar button items onto the bar. and put a fixed space in-between the two.
首先,您需要定义 Web 视图,以便它实际上知道它现在正在做的所有事情是试图找到要在这里运行的内容,请参阅 youtube 上的教程等,这是我用于我的代码,只是设置它。首先,您要将 web 视图放入视图控制器并在其底部添加一个工具栏。在栏上添加四个栏按钮项目。并在两者之间放置一个固定的空间。
then you need to set the styles of them do this by going to attributes inspector> button type > choose style choose the following for the button 1st one is rewind 2nd is forward 3rd one is refresh last one is Cancel.
然后你需要设置它们的样式通过转到属性检查器>按钮类型>选择样式为按钮选择以下第一个是倒带第二个是前进第三个是刷新最后一个是取消。
then control click and drag the button to the web view it will give you the options for it like load rewind and refresh.
然后控制单击并将按钮拖动到网络视图,它将为您提供诸如加载倒带和刷新之类的选项。
then go to your storyboard and make sure you have you main and header files connected do this by selected the view controller in the storyboard files, then change the class to the view controller you want to hook up to. then hit enter
然后转到您的故事板并确保您已连接主文件和头文件,通过在故事板文件中选择视图控制器来执行此操作,然后将类更改为要连接的视图控制器。然后按回车
go to your header file(.h) and insert the following code,
转到您的头文件(.h)并插入以下代码,
@property (nonatomic, strong) IBOutlet UIWebView *webView;
put it under the @interface with brackets but make sure that the code is not inside of the brackets.
将它放在带有括号的@interface 下,但要确保代码不在括号内。
then what you need to do is go to your main file(.m) and insert the following code like this
然后你需要做的是转到你的主文件(.m)并像这样插入以下代码
@interface WebViewController ()
@end
@implementation WebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//custom initialization
}
return self;
}
- (void)viewDidLoad {
NSURL *url = [NSURL URLWithString:@"https://www.google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url]; [_webView loadRequest:requestURL];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
accept obviously you need to replace the void or just past into the right places Then build and Run your code use iOS simulator iPhone 6.
显然接受您需要替换空白或刚刚过去到正确的位置然后使用iOS模拟器iPhone 6构建并运行您的代码。
Hope this helps have a nice day!
希望这有助于度过愉快的一天!
回答by Roger
You should be using the wrong property webFrame
of WebView
instead of mainFrame
你应该使用了错误的性质webFrame
的WebView
,而不是mainFrame
if let url = NSBundle.mainBundle().URLForResource("index", withExtension: "html"){
editorWebView.mainFrame.loadRequest(NSURLRequest(URL: url))
}
回答by real 19
I don't think you are doing anything wrong. Its just a bug
我不认为你做错了什么。它只是一个错误