Cant Get the activity indicator to show on iPhone app

前端 未结 2 2114
情深已故
情深已故 2021-01-17 02:04

I have a view which is created in IB. inside it I have a scroll view created programmatically. Within the scroll view I connect to a web service and fetch the content and th

2条回答
  •  生来不讨喜
    2021-01-17 02:27

    What I have found so far after multiple times facing above problem with activity indicator.

    • Activity indicator and the function (or method or piece of code) that is required to be executed after appearance of activity indicator both can't run on main thread. If it is so activity indicator will not appear. The solution is to run activity indicator on main thread and the function in a background thread.
    • I have also faced a case in which the function followed by activity indicator can't run in a background thread. In my case it was playing a music file using MPMoviePlayerController that can't be executed in a background thread. What I did to solve this issue was to run activity indicator in the main thread and then used an NSTimer to call my method after a delay that was good enough for activity indicator to appear and start animating.
    • I have also found that activity indicator must be called in performSelectorOnMainThread and should be added as a subview on the top view of given viewController once it starts animating. Once it is not needed it should be removed by calling removeFromSuperView method.

提交回复
热议问题