Activity Indicator Not start Animating when the view controller is navigate to another view controller

走远了吗. 提交于 2019-12-08 01:26:56

问题


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!



来源:https://stackoverflow.com/questions/5879582/activity-indicator-not-start-animating-when-the-view-controller-is-navigate-to-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!