How to add a UIView above the current UITableViewController

后端 未结 20 853
旧时难觅i
旧时难觅i 2020-11-27 11:57

I have difficulty adding a subview (UIView) from within the viewDidLoad method of a UITableViewController

This works:

[self.view addSubview:self.prog         


        
20条回答
  •  甜味超标
    2020-11-27 12:40

    I had a similar problem where I wanted to add a loading indicator on top of my UITableViewController. To solve this, I added my UIView as a subview of the window. That solved the problem. This is how I did it.

    -(void)viewDidLoad{
        [super viewDidLoad];
        //get the app delegate
        XYAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    
        //define the position of the rect based on the screen bounds
        CGRect loadingViewRect = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 50, 50);
        //create the custom view. The custom view is a property of the VIewController
        self.loadingView = [[XYLoadingView alloc] initWithFrame:loadingViewRect];
        //use the delegate's window object to add the custom view on top of the view controller
        [delegate.window addSubview: loadingView]; 
    }
    

提交回复
热议问题