iphone - UIActivityIndicatorView 不会停止动画
我有一个 UIActivityIndicatorView,它显示一条消息,指示用户当用户切换视图或单击按钮时定向到另一个视图时,正在加载下一个视图。 我添加了 UIActivityIndicatorView,以便我从 api 获取要在当前视图中显示的数据可以在启用用户交互之前完成。 当当前视图在后台加载时,UIActivityIndicatorView 会使用等待消息正确地进行动画处理。 然而,即使视图加载完成后,UIActivityIndicatorView 也不会停止动画并永远继续! 我已经尝试过 [stop Animating] 和 removefromSuperview 但似乎都不起作用。 我需要紧急解决这个问题。
代码如下: -(void)显示工作进行中 { 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];
}
I have a UIActivityIndicatorView that displays with a message to indicate to the user that the next view is loading when the user switches views or is directed to another view on say a button click. I have added the UIActivityIndicatorView so that the data that im fetching to be displayed in the current view from an api can complete before user interaction is enabled.
The UIActivityIndicatorView animates correctly with the wait message as the current view loads in the background. However even after the view loading is complete, the UIActivityIndicatorView doesnt stop animating and continues forever!!
I have tried both [stop Animating] as well as removefromSuperview but neither seem to work. I need to resolve this issue urgently.
Heres the code:
-(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你能发布你的代码吗? 也许您可以用另一个 UIActivityIndicatorView 替换第一个 UIActivityIndicatorView,或者在它开始动画之前调用 sopAnimating 选择器?
也许是更好的解决方案:
在调用 stopAnimating 选择器之后(或之前)放置一个 NSLog(@"Is the function called?") ,以便您可以(在日志中)查看调用“stopAnimating”选择器的选择器是否被调用。
Can you post your code? Maybe you replace the first UIActivityIndicatorView by another or call the sopAnimating selector before it starts animating?
Maybe a better solution:
Place a NSLog(@"Is the function called?") after (or before) you call the stopAnimating-selector so you can see (in the log) if the selector which calls the 'stopAnimating'-selector is called.