Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting different behaviour when replacing a subview created in the Interface Builder vs one created in code?
    primarykey
    data
    text
    <p>I have a cocoa <code>WebView</code> inside of an <code>NSSplitPane</code> as a subview of one of the split pane's Custom Views. This serves as a preview of some HTML content. To smooth the transition when updating the preview</p> <ol> <li>I make an <code>NSImageView</code> from the <code>WebView</code></li> <li>Replace the <code>WebView</code> with the <code>NSImageView</code></li> <li>Load the new html into the <code>WebView</code></li> <li>Replace the <code>NSImageView</code> with the updated <code>WebView</code> when the html has finished loading</li> </ol> <p>This is the gist of the code is:</p> <p>From the header</p> <pre class="lang-cpp prettyprint-override"><code>NSImageView *previewImageView; NSString *content; @property (strong) IBOutlet NSView *previewContainer; @property (strong) IBOutlet WebView *previewWebView; </code></pre> <p>From the class</p> <pre class="lang-cpp prettyprint-override"><code>- (void)updatePreview { previewImageView = [self imageViewFromWebView:previewWebView]; [[previewContainer animator] replaceSubview:previewWebView with:previewImageView]; [[previewWebView mainFrame] loadHTMLString:content baseURL:nil]; } - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { [[previewContainer animator] replaceSubview:previewImageView with:previewWebView]; } </code></pre> <p>This code does not work correctly if the <code>WebView</code> is defined in the <code>xib</code> file with the referencing outlet set to the <code>previewWebView</code> and the frame load delegate set. The web view is initially shown correctly, gets swapped for the image view ok, but when swapped back does not get displayed.</p> <p>If I instead define the <code>WebView</code> in code</p> <pre class="lang-cpp prettyprint-override"><code>// inside of viewDidAppear NSRect frame = [previewContainer frame]; NSRect webViewFrame = NSMakeRect(0, 0, frame.size.width, frame.size.height); previewWebView = [[WebView alloc] initWithFrame:webViewFrame]; [previewWebView setUIDelegate:self]; [previewWebView setFrameLoadDelegate:self]; [previewWebView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; [previewContainer addSubview:previewWebView]; </code></pre> <p>and not the interface builder, the swapping code works as expected. Any ideas as to what may be different about how I'm defining the <code>WebView</code> in code that makes it work but not when define in the interface builder?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload