Does UIActivityIndicator require manual threading on iPhone

前端 未结 5 755
滥情空心
滥情空心 2020-12-13 02:56

I am running creating an iPhone application which performs a costly operation and I wanted to create an activityIndicator to let the user know the application has not frozen

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 03:29

    Yes, you need to put your operation in a separate thread while the UIActivityIndicatorView calls remain on the main thread.

    Here's why: If you start animating your indicator view then immediately begin your process, your process will block until finished, and the user will never see any "activity."

    Instead, start animating the indicator, then pop a new thread for your process. Use notifications, a delegate pattern, or performSelectorOnMainThread:withObject:waitUntilDone: to let the main thread know that the process is finished. Then stop the animation and continue.

    This will ensure that the user knows something is happening while your process does its thing.

提交回复
热议问题