Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity Indicator View not spinning

I have below code where I am loading some link in webview.

- (void)viewDidLoad
{
    mySpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [self openWebPage:fileName];
    [self.view addSubview:myWebView];
    [self.view addSubview:mySpinner];
    mySpinner.center = CGPointMake(self.view.frame.size.width / 2.0, 100);
}

-(void)openWebPage:(NSString*)address {
    NSURL*url=[NSURL URLWithString:address];
    NSURLRequest*request=[NSURLRequest requestWithURL:url];
    myWebView.scalesPageToFit = NO;

    [myWebView loadRequest:request];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {

    UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error!!!" message:@"Please make sure you are connected to 3G or Wi-Fi." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
    [errorView show];
    mySpinner.hidden = YES;
    [mySpinner stopAnimating];
}


-(void)webViewDidStartLoad:(UIWebView *)webView2 {
    NSLog(@"webViewDidStartLoad");
    mySpinner.hidden = NO;
    [mySpinner startAnimating];
    NSLog(@"step 1");
    NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 2 ];
    [NSThread sleepUntilDate:future];
    NSLog(@"step 2");
}

-(void)webViewDidFinishLoad:(UIWebView *)webView2 {
    NSLog(@"webViewDidFinishLoad");
    mySpinner.hidden = YES;
    [mySpinner stopAnimating];

}

What I am doing is at webViewDidStartLoad I am displaying spinner and starting animating using [mySpinner startAnimating];, but it didn't spin. It just stays as it is (no spinning).

Any idea what is going wrong?


Edit 1

I have webview delegate @interface WebDetailsViewController : UIViewController<UIWebViewDelegate>

Also I have added [NSThread sleepUntilDate:future]; just to verify whether activity indicator view is animating or not.

Below is what I have from NSLog

2013-06-23 16:29:28.843 GulfLab[2048:907] webViewDidStartLoad
2013-06-23 16:29:28.845 GulfLab[2048:907] step 1
2013-06-23 16:29:30.847 GulfLab[2048:907] step 2
2013-06-23 16:29:31.836 GulfLab[2048:907] webViewDidFinishLoad

Edit 2

Well well well the problem is in below line...

[UIView  beginAnimations: @"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: secondView animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

Below is what I have...

One first view controller, I have buttons and when I click those button I am coming to second view controller and there I am displaying the web file based on button pressed.

My client wanted some effect while coming to second view and for that I added above code. But because of that, I am facing the activity problem.

Any idea what changes do I need to do?


On further investigation I found that problem is in this line...

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];

but I need this line as else animation is not happening...

Also today I noticed that if I touch webview, then it starts animating

Grrr... someone help me

like image 790
Fahim Parkar Avatar asked Jun 23 '13 13:06

Fahim Parkar


1 Answers

If somebody runs into a similar problem where there Indicator is not spinning:

Make sure the Animating property is set in your storyboard.

Activity Indicator Animating

like image 154
RWIL Avatar answered Oct 27 '22 01:10

RWIL