Author Topic: How to Display an Activity Indicator in a Scene with a Table View  (Read 7027 times)


  • Administrator
  • *****
  • Posts: 719
    • View Profile
If you are fetching data from the web to fill a table view and want to display an activity indicator in the center of the view while waiting for data, you can add the activity indicator to the AppDelegate window, which makes it handy to reuse from multiple scenes.

You can instantiate and set up the activity indicator like this:

Code: [Select]
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Set the activity indicator to the center of the main window = self.window!.center
        self.activityIndicator.hidesWhenStopped = true
        return true

To use the activity indicator in a particular scene, bring it to front first:

Code: [Select]

All the best!
Kevin McNeish
Author of Learn to Code in Swift:
Check out our Robot Tic-Tac-Toe app:
« Last Edit: November 15, 2015, 10:10:32 AM by kjmcneish »