I’m missing something about how UIActivityIndicatorView and NSTimer work together.
I’ve added this UIActivityIndicatorView in Interface Builder with the following settings:


The UIWebView is instantiated as self.webV and the UIActivityIndicatorView as self.indicator.
I have the following code in the implementation file:
-(void)viewDidLoad
{
[super viewDidLoad];
//Create UIWebView.
if (!self.webV)
{
self.webV = [[UIWebView alloc] init];
}
self.webV.delegate = self;
//Load web page.
NSString *baseURLString = @"myURL.com";
NSString *urlString = [baseURLString stringByAppendingPathComponent:@"myURL.com"];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0/2.0 target:self selector:@selector(timerLoad) userInfo:nil repeats:YES];
[self connectWithURL:urlString andBaseURLString:baseURLString];
}
-(void)timerLoad
{
if (!self.webV.loading)
{
[self.indicator stopAnimating];
}
else
{
[self.indicator startAnimating];
}
}
But when the UIWebView loads, no activity indicator shows up. What am I doing wrong or leaving out?
Thanks for the help, folks.
I’m really not sure on what the behaviour of the
UIActivityIndicatorViewis supposed to be if you repeatedly call start/stop on it. I am reasonably sure it isn’t meant to be used that way 🙂So, even though your question is specific to
NSTimerandUIActivityIndicatorView, it may be helpful to understand that you should approach your solution differently.Instead of using a timer that repeatedly calls
[self.indicator startAnimating]every half-second, you should use the webview delegate methods to toggle theUIActivityIndicatorViewon and off.