Search code examples
iosxcodeios6uiactivityindicatorviewactivity-indicator

Where to add activity indicator view?


I have two view controllers - I will simply call them A and B to help you understand with ease.

A view controller has a button linked to B by storyboard (not manually coded). And, B view controller retrieves bunch of json data from DB server in viewDidLoad method. Because retrieving json data takes some time, I need to add a activity indicator to let users know it's doing something - not frozen. However, I'm not quite sure where I should add the activity indicator view.

If you were in my shoes, where would you add it?


Solution

  • If you have a blocking call in viewDidLoad that will cause the UI to freeze on A before moving to B so I would suggest adding the Activity Indicator on A. Although you may notice that because of the blocking call to the DB, your UI changes immediately before the blocking call also get frozen and you won't see any UI change.

    The way I usually handle this is by spawning a new thread for the blocking call thus freeing up the main thread for UI and then adding an Activity Indicator where necessary (on A or B depends on design but I would recommend showing it on B in this case from a usability POV).

    Just to avoid the hassle of managing all this on my own, I usually end up using something like MBProgressHUD or a similar library which are much easier to manage.