Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bobbypotluck

macrumors member
Original poster
Feb 18, 2009
70
0
I'm having trouble figuring out the correct layout to add the netowrk activity indicator to my UIWebviews.

The problem:
I have a tab-based app with only some tabs that UIWebViews. Each of these have their own ViewController Files.

My current setup:
I have this line of code in my app delegate.h file
Code:
@property (nonatomic, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;

I have this code in each ViewController.m file
Code:
- (void)webViewDidStartLoad:(UIWebView *)webView
{
	// starting the load, show the activity indicator in the status bar
	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = YES;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
	// finished loading, hide the activity indicator in the status bar
	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = NO;
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
	// load error, hide the activity indicator in the status bar
	[UIApplication sharedApplication].isNetworkActivityIndicatorVisible = NO;
	
	// report the error inside the webview
	NSString* errorString = [NSString stringWithFormat:
							 @"<html><center><font size=+5 color='red'>An error occurred:<br>%@</font></center></html>",
							 error.localizedDescription];
	[blogPage loadHTMLString:errorString baseURL:nil];
}

I've tried just adding import appdelegate.h to each viewcontroller.m file but it still says that it wont work and gives me an error. i feel like i'm missing a really big concept here about the activity indicator and how it should be implemented. my codes a mess, i know. any help or examples are appreciated.
 

seepel

macrumors 6502
Dec 22, 2009
471
1
The code

Code:
[UIApplication sharedApplication]

returns the shared application object, not your delegate object.

Right this is probably what you want.
Code:
[[UIApplication sharedApplication] delegate];

Then you will probably get a warning when calling your function but this can be taken care of by casting the delegate to your custom delegate class.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
You have the wrong name. It should be this

Code:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

You're trying to set the getter.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.