Activity Indicator Not start Animating when the vi

2019-05-21 10:28发布

问题:

I currently starting the activity indicator before pushing another view controller but it is not start animating the activity indicator.

[activityindicator startanimating];

[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];

[activityindicator stopanimating];

回答1:


Create a NSThread as call a selector as follows :

[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];  
// Some code  
[spinner stopAnimating];  
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];  

threadStartAnimating :

-(void)threadStartAnimating:(id)data  
{  
[spinner startAnimating];  
}  


回答2:

Try this code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  

[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;    

[self performSelector:@selector(navigatetodeals) withObject:nil afterDelay:.5];

}
-(void)navigatetodeals
{

    yourViewController *d = [[yourViewController alloc]initWithNibName:@"yourView" bundle:nil];

[self.navigationController pushViewController:yourViewController animated:YES];


}


回答3:

You need to use a performSelectorInBackground or something. Because you use the calls in 1 method, the UI doesn't get the chance to update therefor you do not see the activityindicator.

So for your case:

[activityindicator startanimating];  [self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[self performSelectorInBackground:@selector(stopAnimating) :nil];

then create a method like:

-(void)stopAnimating
{
[activityindicator stopanimating];
}

You could use a sleep or something (like sleep(1)) to show the activityindicator because just showing them when you push a view won't do it, because its done in no-time...

Hope this helps!