Search code examples
iosuitableviewuiactivityindicatorview

UIActivityIndicatorView in the same hierarchy of UITableView in UITableViewController


I have a UIViewController and I dropped a UITableView and UIActivityIndicatorView in the same hierarchy and it's working fine.

But then I have a UITableViewController, with a UITableView of course, and I try to drop a UIActivityIndicatorView at the same hierarchy as the Table View but with no luck. I know that there's a problem with UITableViewController and UIViewController with Table View but how to solve?

These two screenshots will help to understand the problem.

The way I want it to be:

enter image description here

The way it turns out:

enter image description here


Solution

  • The problem is that with the UIViewController it has a self.view as the root view where you can add any sub-items as you did , put you can't do this at least in IB with UITableViewController as the root view is the table itself

    First way

    add it in code and control is position as the tableView scrolls so change it's frame in scrollViewDidScroll so it's stay at center of screen during the loading

    Second way

    add it to the main window of the app and remove it when loading finishes