Quote:
Originally Posted by at0m87
In my WebViewController, there is a UIWebview.
i wrote in the activity code to show the spinning wheel while the webpage loads:
Code:
-(void)showWebView{
NSURL *url = [NSURL URLWithString:loginObj.loginURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(spin) userInfo:nil repeats:YES];
}
//--activity indicator to show the loading of webpages
- (void)spin{
if (!myWebView.loading){
[activity stopAnimating];
NSLog(@"Stop Spinning");
}
else{
[activity startAnimating];
NSLog(@"Spinning");
}
}
The method is still running even though i have exited the view as the debugger is printing "stop spinning" endlessly. How do i stop this method from running when i exit from the view with the UIWebView?
|
The particulars of how to stop depend on your implementation details. However, a better place to put the stopAnimating call would in in the webViewDidFinishLoad-method.
Another issue is that your if-clause is problematic: if ( !myWebView.loading )
If we look at it in more detail, what happens if myWebView is nil? Then myWebView.loading is also nil, and the clause evaluates to true. That coupled with the fact that you're not stopping the NSTimer is most likely causing the behavior you're witnessing. If you put the stopAnimating call into webViewDidFinishLoad, you can get rid of the NSTimer and also get rid of this problem altogether.