我有两个类:ClassA
和ClassB`。
ClassA
实施UIViewController
。ClassB
实施NSObject
。我在classA的方法中有startAnimating UIActivityIndicator
,同时我需要调用其中一个B类方法。执行B类方法后,我将调用新的classA方法,然后调用Stop Animating UIActivityIndicator
。除了StopAnimating
,每件事都很好。请帮我找到解决方案。我不知道线程,如果我使用线程,它会解决我的问题吗?
线程似乎是一种解决这个问题的复杂方法。为什么不在A类中保留UIActivity指示器,并在B中从A类调用的方法中停止动画.Woo听起来很复杂。
没有理由不能将活动指示器的指针传递给任何类。
如果这对你不起作用,我会查看通知而不是沿着多线程路由
要解决此问题,请使用以下代码
在.h文件中声明UIActivity指示符对象。
在要停止动画的位置调用以下方法。
[NSThread detachNewThreadSelector:@selector(stopAnimation) toTarget:self withObject:nil];
- (void)stopAnimation{
[activityIndicatorView stopAnimating];
}