UIActivity指示符在调用NSObject类的函数后不会停止

问题描述 投票:0回答:2

我有两个类:ClassA和ClassB`。

  • ClassA实施UIViewController
  • ClassB实施NSObject

我在classA的方法中有startAnimating UIActivityIndicator,同时我需要调用其中一个B类方法。执行B类方法后,我将调用新的classA方法,然后调用Stop Animating UIActivityIndicator。除了StopAnimating,每件事都很好。请帮我找到解决方案。我不知道线程,如果我使用线程,它会解决我的问题吗?

iphone objective-c xcode uiactivityindicatorview
2个回答
0
投票

线程似乎是一种解决这个问题的复杂方法。为什么不在A类中保留UIActivity指示器,并在B中从A类调用的方法中停止动画.Woo听起来很复杂。

没有理由不能将活动指示器的指针传递给任何类。

如果这对你不起作用,我会查看通知而不是沿着多线程路由


0
投票

要解决此问题,请使用以下代码

在.h文件中声明UIActivity指示符对象。

在要停止动画的位置调用以下方法。

[NSThread detachNewThreadSelector:@selector(stopAnimation) toTarget:self withObject:nil];


- (void)stopAnimation{
    [activityIndicatorView stopAnimating];
}
© www.soinside.com 2019 - 2024. All rights reserved.