Add view over tableview (UITableViewController)

Mittchel picture Mittchel · Sep 2, 2013 · Viewed 34.8k times · Source

Situation: I've got a UITableViewController loading some data asynchronously from a service. During this time I would like to place a full screen (except navigation bar) view over the table view showing my custom indicator and text.

Problem: The problem I'm facing is that when my custom view (it has a red background) is placed over the UITableView the lines of the table view are shown trough my custom view (see image below).

What I tried: I tried to use insertBelow and above, didn't work. I also tried to do: tableview.Hidden = true, but this also hides the custom view for some reason as seen on image 2.

See lines

Image1: For some reason I can see the lines threw my view.

Hidden true

Image 2: Tableview + custom view gone when hidden = true used.

My code:

        public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        UIView view = new UIView (new RectangleF (0, 0, this.TableView.Frame.Width, this.TableView.Frame.Height));
        view.BackgroundColor = UIColor.Red;

        this.TableView.AddSubview (view);

        TableView.Source = new SessionTableViewSource ();
    }

Answer

sagus_helgy picture sagus_helgy · Sep 17, 2014

You can use self.navigationController.view as view for adding subview.