Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I added a WebView to my Cocoa app and it's generating an error

I added a WebView to my app and I'm loading a page into it using this code:

-(void)awakeFromNib{
    NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
    NSString *htmlPath = [resourcesPath stringByAppendingString:@"/calendarHTML/test.html"];
    [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]]; 
}

However, when I run the app I receive the following error:

Layout still needs update after calling -[WebHTMLView layout].  
WebHTMLView or one of its superclasses may have overridden 
-layout without calling super. Or, something may have dirtied 
layout in the middle of updating it.  Both are programming errors in 
Cocoa Autolayout.  The former is pretty likely to arise if some 
pre-Cocoa Autolayout class had a method called layout, but it should be fixed.!

error log

What is causing this problem?

like image 329
小弟调调 Avatar asked Apr 19 '12 00:04

小弟调调


2 Answers

This is caused by the fact that the nib containing the window that you have placed the WebView into is using the new Auto Layout feature, introduced in Lion.

When a nib file has auto layout enabled, the window will call the -layout method on all NSView objects in the window.

This causes a problem with WebView because it had a method named -layout before it the method was added to the NSView API in Lion, and WebView's layout method does not understand auto layout.

Probably the best fix for the time being is to use the old autoresizing mask method of laying out the views in your window. As Xcode now creates nib files with autolayout enabled, you need to disable it yourself.

You can do that in the File inspector for your nib file, by disabling the Use Auto Layout checkbox.

interface builder inspector

After you do this, you'll need to make sure that all the views in the nib have the correct autoresizing settings in the Size tab of the view inspector.

like image 197
Rob Keniger Avatar answered Nov 16 '22 23:11

Rob Keniger


Note that you can safely ignore that log message for WebViews.

like image 45
corbin dunn Avatar answered Nov 16 '22 23:11

corbin dunn