How do I show and start animating a UIActivityIndicatorView from within a method

。_饼干妹妹 提交于 2019-12-02 00:47:52
V1ru8

I assume you are doing some expensive work in this method and while that work is being performed, you want the activity indicator to spin. Expensive work should NOT be done on the main thread (iOS might kill your app!). Put your expensive work on a separate thread with:

- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg

...and when the method (aSelector) is done, call:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait 

...and there you stop the activity indicator.

Never call any UI code from within a non-main thread!

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