Activity Indicator Not start Animating when the vi

2019-05-21 10:57发布

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];

3条回答
Emotional °昔
2楼-- · 2019-05-21 11:08


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];  
}  
查看更多
虎瘦雄心在
3楼-- · 2019-05-21 11:09

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!

查看更多
混吃等死
4楼-- · 2019-05-21 11:16

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];


}
查看更多
登录 后发表回答