活动指标只出现一秒钟

时间:2013-01-09 16:26:23

标签: ios uiactivityindicatorview activity-indicator

我有2个观点 1)A 2)B

当我从视图A转到视图B时,加载需要很长时间,所以我在segue中添加了一个活动指示器。

我的问题是,当我转到视图B时,我的屏幕在视图A中冻结(加载)并且仅在瞬间显示,它在进入视图B之前显示活动指示符。

如何在开始加载之前确保活动指示符出现。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

[self useActivityIndicator];


if ([[segue identifier] isEqualToString:@"ShowAdsDetail"])
{
    //do anything that needs to be done



}

}

    -(void)useActivityIndicator{

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityView startAnimating];
subView.hidden = NO;

}

2 个答案:

答案 0 :(得分:1)

我有一个类似的问题,UIActivityIndi​​cator动画太快了。 segue正在推动下一个视图控制器,几乎没有显示活动指示器。

如果这可以帮助其他人 - 我能够通过实现performSelector:withObject:afterDelay来修复它,然后在removeSpinner方法中调用我的performSegueWithIdentifier方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    [self.spinner startAnimating];
    [self performSelector:@selector(removeSpinner:) withObject:self.spinner afterDelay:2.0];
}

- (void)removeSpinner: (UIActivityIndicatorView *)spinner {
    [self.spinner stopAnimating];
    [self.spinner removeFromSuperview];
    [self performSegueWithIdentifier:@"showMyPlans" sender:nil];
}

答案 1 :(得分:0)

只需更改您的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      [self useActivityIndicator];
   });

   if ([[segue identifier] isEqualToString:@"ShowAdsDetail"])
   {
      //do anything that needs to be done
   }
}



-(void)useActivityIndicator
{
       dispatch_async(dispatch_get_main_queue(),^{
         [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
         [activityView startAnimating];
         subView.hidden = NO;
      });
}