Why won't my UIActivityIndicatorView stop animating?

吃可爱长大的小学妹 提交于 2019-12-05 18:38:40

Are you trying to do this from a background thread? An easy and definitive test would be to add:

NSLog(@"thread: %@", [NSThread currentThread]);

check if your activityIndicator isn't nil:

NSLog(@"activityIndicator: %@", activityIndicator);

OK. I did my experiment and sure enough, it worked flawlessly when I added the activity indicator as a subview of viewcontroller's view. However, when I then used that new simpleton project to try it as a subview to window it also worked. Obviously a bug in my code and it needs more inspection.

I will award both Eimantas with the answer as the debug notion was helpful in my solution.

if your log is nil then do this:

in ".h" declare :

__strong UIActivityIndicatorView *activityIndicator

the __strong avoid ARC and then you can remove and stop the activityIndicator.

[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
Jeremy Butler

If you are adding it to the superview more than one time it will not work.

Try putting

[superView addSubview:activityIndicator];

into the

if( activityIndicator == nil ) {

condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!