How implement a UIActivityIndicatorView when the UIWebView is Loading? (iPhone ObjC)

后端 未结 3 2202
栀梦
栀梦 2020-12-17 22:08

I want to know how to implement an activityIndicator in a WebView based app, I wrote the following code but the indicator does not appear.

The webview load file loca

3条回答
  •  一个人的身影
    2020-12-17 22:28

    Why are you setting your activity indicator to nil in your init?

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {     
      if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {      
         //Initialization code      
         m_activity = nil;  
       }    
       return self; 
    }
    

    The call to super initialized your indicator from your XIB (assuming you connected it to your outlet in IB), but then you are setting the reference to nil after it's been initialized. Remove that line. Then go back into interface builder and set the "Hide when stopped" checkbox. Now you can simplify your code that displays the indicator:

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
       [m_activity stopAnimating];  
    }
    
    - (void)webViewDidStartLoad:(UIWebView *)webView {     
       [m_activity startAnimating];     
    }
    

    The "Hide when stopped" causes the indicator to hide when you stop it from animating.

提交回复
热议问题