views:

1760

answers:

1

Hey guys, I have a big problem with the UIWebView in iPhone SDK. I have a TabBarApplication with one WebView on each Tab (except the first).

Because it takes quiet a while to load the views I'd like to show an activity indicator.

Here is the code I'm using in order to do that:

-(void)webViewDidStartLoad:(UIWebView *) portal {

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES; }

-(void)webViewDidFinishLoad:(UIWebView *) portal{
 [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
}

It doesn't work this way... My WebView in the first tab is called "portal", that's why I entered it above, but the same problem exists if I use WebView.

Any ideas? Can't be true that this is soooo difficult. I'm searching for a clue quiete a while now and found nothing which helped me to build such a (think it's easy) activityindicator.

Thanks a lot for your effort!

Greets from Germany Tobias

A: 

I typically use a UIActivityIndicatorView.

If you have a Navigation Controller on top of the web view it works perfectly:

-(void)webViewDidStartLoad:(UIWebView *) portal {
UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
UIBarButtonItem *actItem = [[UIBarButtonItem alloc] initWithCustomView:actInd];

self.navigationItem.rightBarButtonItem = actItem;

[actInd startAnimating];
[actInd release];
[actItem release];
}

To get rid of the indicator:

-(void)webViewDidFinishLoad:(UIWebView *) portal{
 self.navigationItem.rightBarButtonItem = nil;
}

If you aren't using a Navigation Controller then I would simply use either the larger style, UIActivityIndicatorViewStyleWhiteLarge OR place the view on top of a dark semi-transparent view on the screen and then remove them on load finish.

Matthew McGoogan
Thanks for your fast help!The activityIndicator does not shop up in my App :(Do you have any ideas?I just copy and paste it exactly the way you postet it.Is there a problem with my TabBar?
Tobias
Well that code was if you had a UINavigationController that your controller witht he webview was inside (meaning you would have a nav bar at the top). If you don't then you would need to add the Activity Indicator to another view, [portal addSubview:actInd] for instance. What is your controller scheme? UITabBarController > ??? > UIWebView
Matthew McGoogan
Ahh, I see.I have created a TabBar based Application and just droped the webviews in each element.Each Tab has it's own controller for the webview.Hope you understand what I mean? I'm completely new to Objective C and iPhone SDk...Thanks so much for your help!PS.My Code now looks like this:[code]- (void)webViewDidStartLoad:(UIWebView *) portal { UIActivityIndicatorView *actInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; [portal addSubview:actInd]; [actInd startAnimating]; [actInd release];}[/code]
Tobias
So the view is showing up? So you know you'll have to maintain a pointer to the ActivityIndicator if you want to remove it in the didFinishLoad method.
Matthew McGoogan
The WebView is showing up but the ActivityIndicator Subview doesn't.It seems like the App does not launch the DidStartLoad method, because it didn't worked with my NetworkActivityIndicator, too.
Tobias
Where are you putting the webview delegate methods? Make sure whatever controller or object you put them in is set as the delegate of the UIWebView.
Matthew McGoogan
Can't imagine it's so hard to add an activityindicator....Would you mind having a look at my App?Please send me an email to: ruhrpotts-proud[at]iszene.com
Tobias