我现在在推送另一个视图控制器之前启动了活动指示器,但它没有开始为活动指示器设置动画。
[activityindicator startanimating];
[self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[activityindicator stopanimating];
答案 0 :(得分:10)
创建一个NSThread作为调用选择器,如下所示:
[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];
}
答案 1 :(得分:1)
试试这段代码:
- (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];
}
答案 2 :(得分:0)
您需要使用performSelectorInBackground或其他东西。因为您使用1方法中的调用,所以UI没有机会更新,因此您没有看到activityindicator。
所以对你的情况来说:
[activityindicator startanimating]; [self.navigationcontroller pushviewcontroller:viewcontroller animated:YES];
[self performSelectorInBackground:@selector(stopAnimating) :nil];
然后创建一个方法,如:
-(void)stopAnimating
{
[activityindicator stopanimating];
}
你可以使用睡眠或其他东西(比如睡眠(1))来显示activityindicator,因为当你推动视图时只显示它们就不会这样做,因为它是在没有时间完成的......
希望这有帮助!