Ipad 需要活动指示器的帮助吗

Ipad 需要活动指示器的帮助吗,ipad,uiactivityindicatorview,Ipad,Uiactivityindicatorview,我的活动指示器无法工作 这是我得到的- -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; //Create an instance of activity indicator view UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20

我的活动指示器无法工作

这是我得到的-

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
//Create an instance of activity indicator view
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
//set the initial property
[activityIndicator stopAnimating];
[activityIndicator hidesWhenStopped];
//Create an instance of Bar button item with custome view which is of activity indicator
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
//Set the bar button the navigation bar
[self navigationItem].rightBarButtonItem = barButton;
//Memory clean up
[activityIndicator release];
[barButton release];
}
代码的一部分,用来启动然后结束-

...
    else if ([theSelection isEqualToString: @"Update statistics"])
    {
        [self startTheAnimation];
        [updateStatistics  updateThe2010Statistics];
        [self stopTheAnimation];
    }
...


-(void)startTheAnimation {
    [(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView startAnimating];
}

-(void)stopTheAnimation {
    [(UIActivityIndicatorView *)[self navigationItem].rightBarButtonItem.customView stopAnimating];
}
至少改变:

   [activityIndicator hidesWhenStopped];
致:


或者删除该行,因为默认值为YES。

最有可能的情况是您正在阻塞系统的事件线程:您是否正在执行调用[updateStatistics updateThe2010Statistics]的方法;从某些iAction回调或由系统触发的任何其他方法,例如-viewDidLoad,-viewwillbeen或类似的方法

在这种情况下,长时间运行的任务将阻止事件线程,而事件线程又无法更新活动指示器。尝试执行以下操作:

...
else if ([theSelection isEqualToString: @"Update statistics"])
{
  [self startTheAnimation];
  [self performSelectorInBackground:@selector(doUpdateStatistics) withObject:nil];
}
...

- (void) doUpdateStatistics {
  [updateStatistics  updateThe2010Statistics];
  [self performSelectorOnMainThread:@selector(stopTheAnimation) withObject:nil waitUntilDone:NO];
}

这将在第二个线程上执行统计信息更新,以便事件线程可以正确地更新活动指示器。在更新统计信息结束时,我们在主线程(即事件线程)上再次调用停止动画,以停止活动指示器。

它是否显示但不显示动画,或者甚至不显示?
...
else if ([theSelection isEqualToString: @"Update statistics"])
{
  [self startTheAnimation];
  [self performSelectorInBackground:@selector(doUpdateStatistics) withObject:nil];
}
...

- (void) doUpdateStatistics {
  [updateStatistics  updateThe2010Statistics];
  [self performSelectorOnMainThread:@selector(stopTheAnimation) withObject:nil waitUntilDone:NO];
}