• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating WebView in code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating WebView in code


  • Subject: Re: Creating WebView in code
  • From: Nick Zitzmann <email@hidden>
  • Date: Fri, 2 Apr 2010 15:08:58 -0600

On Apr 2, 2010, at 2:19 PM, Jenny M wrote:

> D'oh, you told me that before and I completely forgot. So I tried
> that, but the page still appears blank. I don't want the page to be
> visible so I didn't set makeKeyOrderFront.
>
> --------------------
> NSRect frame = NSMakeRect(0.0, 0.0, pageSize.width, pageSize.height);
> NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
> styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
> defer:NO];
>
> WebView *myWebView = [[WebView alloc] initWithFrame:frame
> frameName:@"Test Frame" groupName:nil];
> [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
> URLWithString:@"http://www.jenstechs.net/test/testpage.html";]]];
>
> [window setContentView:myWebView];
> --------------------
>
> I also tried setting the content view before loading the request, but
> both still result in blank pages....

There's one more thing. WebView loads requests asynchronously, so you need to block while it is loading the request and laying out the page while taking some time out to run the run loop. So do something like this:

while ([myWebView isLoading])
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	[myWebView setNeedsDisplay:NO];
	[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:1.0] inMode:NSDefaultRunLoopMode dequeue:YES];
	[pool drain];
}
[webView setNeedsDisplay:YES];

When this loop is done, any print operation you perform on the web view ought to work.

Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Creating WebView in code
      • From: "Adam R. Maxwell" <email@hidden>
    • Re: Creating WebView in code
      • From: Jenny M <email@hidden>
References: 
 >Re: Creating WebView in code (From: Jenny M <email@hidden>)
 >Re: Creating WebView in code (From: Nick Zitzmann <email@hidden>)
 >Re: Creating WebView in code (From: Jenny M <email@hidden>)

  • Prev by Date: Re: MutableArray losing contents
  • Next by Date: Re: Implied use of Properties
  • Previous by thread: Re: Creating WebView in code
  • Next by thread: Re: Creating WebView in code
  • Index(es):
    • Date
    • Thread