network Activity Indicator help

Discussion in 'iOS Programming' started by bobbypotluck, Jun 26, 2010.

  1. bobbypotluck macrumors member

    Joined:
    Feb 18, 2009
    #1
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The code

    Code:
    [UIApplication sharedApplication]
    
    returns the shared application object, not your delegate object.
     
  3. seepel macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #3
    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.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    You have the wrong name. It should be this

    Code:
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    You're trying to set the getter.
     

Share This Page