【发布时间】:2009-08-14 08:55:17
【问题描述】:
我有一个 UIActivityIndicatorView,当用户切换视图或点击按钮被定向到另一个视图时,它会显示一条消息,向用户指示下一个视图正在加载。我添加了 UIActivityIndicatorView 以便我从 api 获取要显示在当前视图中的数据可以在启用用户交互之前完成。 当当前视图在后台加载时,UIActivityIndicatorView 会正确地使用等待消息进行动画处理。然而,即使在视图加载完成后, UIActivityIndicatorView 也不会停止动画并永远继续! 我已经尝试过 [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]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 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];
}
【问题讨论】: