开发者

iPhone SDK - WebView activity indicator

开发者 https://www.devze.com 2022-12-17 06:41 出处:网络
I have a big problem with the UIWebView in iPhone SDK. I have a TabBarApplication with one WebView on each Tab (except the first).

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 bu开发者_如何转开发ild such a (think it's easy) activityindicator.

Thanks a lot for your effort!

Greets from Germany Tobias


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号