Bryan Hanson
Bryan Hanson

Reputation: 6213

Another (!) Activity Indicator Issue

Well, after reading a bunch of SO posts on this issue, I still can't fix problems with my activity indicator. This indicator is in a view in a tab under the control of its own view controller. It has a view with a UIWebView which loads a local html page just fine. The view is loaded with initWithNibName and then awakeFromNib. Here's the part I think is relevant:

@implementation HelpViewController
@synthesize webView = _webView;
@synthesize back = _back;
@synthesize forward = _forward;
@synthesize aI = _aI;

- (void) viewDidLoad {
_aI = [[UIActivityIndicatorView alloc]
           initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[_aI stopAnimating];

// Now add the web view

NSString *filePath = [[NSBundle mainBundle]
                      pathForResource:@"Help"
                      ofType:@"html"];

[self.view addSubview:_webView];
_webView.delegate = self;
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
[_webView loadRequest:request];
[super viewDidLoad];
}

-(void) webViewDidStartLoad:(UIWebView *)webView {   
[_aI startAnimating];
_back.enabled = NO;
_forward.enabled = NO;   
}

-(void) webViewDidFinishLoad:(UIWebView *)webView {  
[_aI stopAnimating];

if (webView.canGoBack) {
    _back.enabled = YES;
    _back.highlighted = YES;
}

if (webView.canGoForward) {
    _forward.enabled = YES;
    _forward.highlighted = YES;
}
}

The navigation buttons work fine. The activity indicator was placed in the nib, but in the main view, not on/over/under the webView. In the attributes, I have Hides When Stopped checked. If I check Animating the indicator is always visible and animated, no matter how I navigate through the UIWebView.. If I uncheck Animating, Hidden is automatically checked for me. In this case, the indicator never shows up. So it's either always on or always off.

I've read quite a bit about cases where you need to have the indicator on a different thread. I'm not sure, but I don't think that applies here (I load a local html page but allow users to navigate off and then back to the local page). But, I seem to have some disconnect; perhaps it is the fact that the indicator is in the main view but the pages are in the webView? Or I'm not calling things in the right methods. Or who knows... Thanks for any help!

Upvotes: 0

Views: 304

Answers (1)

JustSid
JustSid

Reputation: 25318

You overwrite _aI in your viewDidLoad and never place it in your view hierarchy, so the object you are sending the messages to is never visible and the activity indicator placed in interface build will never change its state, so thats why its either always animating or hidden.

Upvotes: 2

Related Questions