iphone - UIActivityIndi​​catorView 不会停止动画

发布于 2024-08-02 02:06:39 字数 1665 浏览 6 评论 0原文

我有一个 UIActivityIndi​​catorView,它显示一条消息,指示用户当用户切换视图或单击按钮时定向到另一个视图时,正在加载下一个视图。 我添加了 UIActivityIndi​​catorView,以便我从 api 获取要在当前视图中显示的数据可以在启用用户交互之前完成。 当当前视图在后台加载时,UIActivityIndi​​catorView 会使用等待消息正确地进行动画处理。 然而,即使视图加载完成后,UIActivityIndi​​catorView 也不会停止动画并永远继续! 我已经尝试过 [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]

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];

}

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2024-08-09 02:06:39

你能发布你的代码吗? 也许您可以用另一个 UIActivityIndi​​catorView 替换第一个 UIActivityIndi​​catorView,或者在它开始动画之前调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文