Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 03-26-2009, 04:18 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 25
blacksheep_2011 is on a distinguished road
Default Preload webView

Hi,

is it possible to preload a webView before pushing it to the navigationController. Now the webView begins to load when the webview is visible.

Cya,
Tim
blacksheep_2011 is offline   Reply With Quote
Old 03-28-2009, 08:53 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,050
wuf810 is on a distinguished road
Default

Quote:
Originally Posted by blacksheep_2011 View Post
Hi,

is it possible to preload a webView before pushing it to the navigationController. Now the webView begins to load when the webview is visible.

Cya,
Tim
yeh load it into a UIWebView object. Then when you push the view, and assuming it is a different viewController, then "copy" your preloaded webView into your onscreen webview.

Just because you define an object doesn't mean you have to show it.

Hope this makes sense...M
wuf810 is offline   Reply With Quote
Old 10-14-2009, 01:54 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
dancriel is on a distinguished road
Default

resurrecting an old thread to ask: does anyone have any example code for how to do this?

i have a view, loaded from a nib, which contains a UIWebView. into that web view i am loading html content from an html file in my bundle.

loading the content with loadHTMLString: seems to only work if i do it in my viewDidLoad: method, so you see a blank screen for a second before the content loads. this ruins the page curl animation because it should look like the content is on there already as it's animating.

so, i need to preload this html into the web view before displaying my view but i can't figure it out. halp!
dancriel is offline   Reply With Quote
Old 10-15-2009, 08:11 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 1
peekay is on a distinguished road
Default

I had the same problem. I had a webview in a ViewController that's pushed into a NavigationController stack. The animation started before my webview completed loading.

I solved it using the approach below. Note: I construct my objects programatically but you should be able to use the same idea with nibs:

1. I initialize and load the webview in the ViewController's initXXX function. This starts the loading process. I construct everything else in loadView (or viewDidLoad if using nibs).

2. My ViewController implements UIWebViewDelegate and waits for webViewDidFinishLoad. In this method I simply set a boolean property "ready" to YES and do other initializations as necessary (such invoking JavaScript functions).

3. Now I can init the ViewController, and then only push it to the NavigationController when its "ready" flag turns to YES (observed using Key Value Coding). This way I'm guaranteed the webview is preloaded.

I needed to wait for webViewDidFinishLoad for to fire some JavaScript anyway, so really it's just creating an additional observer to know when the webview has been fully rendered.
peekay is offline   Reply With Quote
Old 10-15-2009, 11:28 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
dancriel is on a distinguished road
Default

thanks for your reply peekay.

loading my html in my viewController's init function does not work, maybe it has something to do with the fact that i'm loading from a nib...?

my viewDidLoad function (where i am currently loading the html) seems like it's getting called only when i add my navigation controller to the view, just as the page curl animation begins.

my code:

root view controller methods to show/hide my view
Code:
static UINavigationController *aboutViewNavigationController;

- (IBAction)showAboutView {
	// load view controller
	NSLog(@"loading about view");
	AboutViewController *viewController = [AboutViewController new];
	viewController.title = @"About";
	
	// add Done button
	UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(hideAboutView)];
	viewController.navigationItem.rightBarButtonItem = cancelButton;
	[cancelButton release];
	
	// insert into nav controller
	UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
	aboutViewNavigationController = [navController retain];
	
	// 20px offset for status bar
	CGRect rect = aboutViewNavigationController.view.frame;
	rect.origin.y -= 20.0;
	aboutViewNavigationController.view.frame = rect;
	
	// display
	NSLog(@"showing about view");
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1.0];
	[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
	[self.view addSubview:aboutViewNavigationController.view];
	[UIView commitAnimations];
		
	[viewController release];
	[navController release];
}

- (void)hideAboutView {
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:1.0];
	[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
	[aboutViewNavigationController.view removeFromSuperview];
	[UIView commitAnimations];
	
	[aboutViewNavigationController release];
}
from AboutViewController

Code:
- (void)viewDidLoad {
	NSLog(@"loading html");
	NSString *path = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
	NSString *htmlContent = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:NULL];
	NSURL *bundleUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
	[webView loadHTMLString:htmlContent baseURL:bundleUrl];
	
	[super viewDidLoad];
}
console shows "loading html" just as the page curl animation starts, but the html content isn't rendered until a split-second after the animation ends. does it really take this long to load ~30 lines of html, or is something preventing the content from rendering right away?

if i move the loadHTMLString: stuff to my AboutViewController's init function it doesn't work at all, i get a white screen when the page flips down and no html loads.
dancriel is offline   Reply With Quote
Old 10-15-2009, 03:36 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
dancriel is on a distinguished road
Default

ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:

i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.

i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.

hope this helps someone else.

there are other ways that you could notify your root view that the webview is finished loading, but this works for me.
dancriel is offline   Reply With Quote
Old 02-02-2010, 12:09 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 4
clawson73 is on a distinguished road
Default I'm having the same issue

Quote:
Originally Posted by dancriel View Post
ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:

i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.

i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.

hope this helps someone else.

there are other ways that you could notify your root view that the webview is finished loading, but this works for me.
Hey
I know this is an old thread but I'm running into the same issue could you please possibly send me the source or how you did this I'm a complete noob and I could use all the help thank you so much
chris
clawson73 is offline   Reply With Quote
Old 06-07-2010, 12:27 AM   #8 (permalink)
New User
 
Join Date: Apr 2010
Posts: 6
brandoncopley is on a distinguished road
Default preloading

Quote:
Originally Posted by dancriel View Post
ok, i came up with a unique solution to this problem. i am now successfully preloading the uiwebview with html content from a local file, and the page curl animation looks good. here's how i did it:

i noticed that the webview was refusing to load the content until it was in view. to solve this, i actually added the entire new view on top of my own view with a very low alpha (0.001), which would get the webview to render without making it visible. i temporarily set my root view controller as the UIWebViewDelegate so the web view would tell me when it was finished loading.

i then wait for the webViewDidFinishLoad: method to fire to apply the page curl animation, setting the alpha of my new About view to 1.0 as the animation starts and passing delegate responsibilities back to the new About view.

hope this helps someone else.

there are other ways that you could notify your root view that the webview is finished loading, but this works for me.

Alright I can do all of this and it worked fine last night, but my mac crashed and I can't get it going again.

I have two viewcontrollers
OneViewController and TwoViewcontroller

So for #1:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];

	oneViewController = [[OneViewController alloc] init];
	[oneViewController.view setAlpha:0.5];
	[self.view addSubview:oneViewController.view];
}

- (void)webViewDidFinishLoad:(UIWebView *)myWebView{
	NSLog(@"finished");
	SecondViewController *sec = [[SecondViewController alloc] init];
	[self.navigationController pushViewController:sec animated:YES];
}
and second view controller

Code:
-(void)viewDidLoad{
	if(_loading == NO){
	_loading = YES;
	NSURL *url = [NSURL URLWithString:@"http://www.apple.com"];
	NSURLRequest *theRequest=[NSURLRequest requestWithURL:url
											  cachePolicy:NSURLRequestUseProtocolCachePolicy
										  timeoutInterval:60.0];
	[myWebView setDelegate:oneViewController];
	[myWebView loadRequest:theRequest];}
	
}
Now the web delegate responds but nothing ever gets pushed - what's up with that? It's like push doesn't work when it's delegated that way. Do I have to do something goofy with my nib?

I found this only works if I insert a OneViewController object into the TwoViewController Nib and then link the oneViewController instance to the OneViewController object.
brandoncopley is offline   Reply With Quote
Old 06-15-2010, 03:09 PM   #9 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
dancriel is on a distinguished road
Default

When webViewDidFinishLoad is called it alloc/inits a new SecondViewController object every time... maybe you should be pushing myWebView onto your main view controller rather than a new instance of SecondViewController.
__________________
My Apps:
EmojiMemory
Psycho
dancriel is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
10 members and 351 guests
.Snipe, AppsImpact, BSH, Cee Oasis, givensur, guusleijsten, HemiMG, NSString, Paul Slocum, SillyHoney
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0