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

发布于 2024-10-07 21:52:49 字数 410 浏览 0 评论 0原文

我有两个类:ClassA 和 ClassB`。

  • ClassA 实现 UIViewController

  • ClassB 实现 NSObject

我在 A 类的方法中有 startAnimating UIActivityIndi​​cator ,同时我需要调用 B 类的方法之一。执行 B 类的方法后,我将调用新的 A 类的方法,然后停止 UIActivityIndi​​cator 动画。这里一切都工作正常,除了 StopAnimating。请帮助我找到解决方案。我不知道线程,如果我使用线程,它能解决我的问题吗?

I have two classes: ClassA and ClassB`.

  • ClassA implements UIViewController.

  • ClassB implements NSObject.

I have startAnimating UIActivityIndicator in classA's method at the same time i need to call one of the Class B's Methods. After executing Class B's method, I'll call new classA's method and then Stop Animating UIActivityIndicator. Here every thing is working fine, except StopAnimating. Please help me to find the solution. I don't know about threads, if I use thread, will it solve my problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

荭秂 2024-10-14 21:52:49

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

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

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

threading seems like a complicated way to solve this. Why not retain a the UIActivity indicator in class A, and stop animating in the method you call in class A from B. Woo sounds complicated.

Theres not reason why you cant pass a pointer the activity indicator to any class.

If this doesn't work for you I'd look at notications rather than going down the multi-threaded route

我恋#小黄人 2024-10-14 21:52:49

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

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

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

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


- (void)stopAnimation{
    [activityIndicatorView stopAnimating];
}

To solve this problem, use the following code

Declare the UIActivity indicator object in the .h file.

Call the following method where you want to stopAnimating.

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


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