0

我有一个 UIActivityIndi​​catorView,它显示一条消息,向用户指示下一个视图正在加载,当用户切换视图或点击按钮时被定向到另一个视图。我添加了 UIActivityIndi​​catorView 以便我从 api 获取要显示在当前视图中的数据可以在启用用户交互之前完成。当当前视图在后台加载时,UIActivityIndi​​catorView 会正确地使用等待消息进行动画处理。然而,即使在视图加载完成后, UIActivityIndi​​catorView 也不会停止动画并永远继续!我已经尝试过 [stop Animating] 和 removefromSuperview 但似乎都不起作用。我需要紧急解决这个问题。

下面是代码:-(void)showWorkInProgress { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

   progressAlert = [[UIAlertView alloc] initWithTitle:@"Loading Data"
                                                           message:@"Please wait..."
                                                            delegate: self
                                               cancelButtonTitle: nil
                                                otherButtonTitles: nil];


   activityView = [[UIActivityIndicatorView alloc]

initWithActivityIndi​​catorStyle:UIActivityIndi​​catorViewStyleWhite]; activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f); [progressAlert addSubview:activityView];

   [activityView startAnimating];

   [progressAlert show];

   [pool drain];

} - (void)viewDidLoad {

   self.title = @"WordLife";
   UIImage *image = [UIImage imageNamed: @"cena.png"];
   UIImageView *imageview = [[UIImageView alloc] initWithImage: image];
   self.navigationItem.titleView = imageview;

   [imageview release];
   self.navigationItem.leftBarButtonItem.title = @"Back";


   [activityView removeFromSuperview];
   activityView = nil;
   [super viewDidLoad];

}

4

1 回答 1

1

你可以发布你的代码吗?也许您将第一个 UIActivityIndi​​catorView 替换为另一个,或者在它开始动画之前调用 sopAnimating 选择器?

也许一个更好的解决方案:
在调用 stopAnimating-selector 之后(或之前)放置一个 NSLog(@"Is the function called?") 以便您可以看到(在日志中)调用 'stopAnimating'-selector 的选择器是否是叫。

于 2009-08-16T13:36:50.717 回答