How to add a UIView above the current UITableViewController

后端 未结 20 799
旧时难觅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:30

    Update for iOS 11:

    It is now possible to add an Subview to UITableView when using AutoLayout constraints to the safe area. These Views will not scroll along the TableView.

    This example places a view below the NavigationBar on top of the UITableView of a UITableViewController

    [self.tableView addSubview:self.topBarView];
    [NSLayoutConstraint activateConstraints:@[
        [self.topBarView.topAnchor constraintEqualToAnchor:self.tableView.safeAreaLayoutGuide.topAnchor],
        [self.topBarView.leadingAnchor constraintEqualToAnchor:self.tableView.safeAreaLayoutGuide.leadingAnchor],
        [self.topBarView.trailingAnchor constraintEqualToAnchor:self.tableView.safeAreaLayoutGuide.trailingAnchor],
        [self.topBarView.heightAnchor constraintEqualToConstant:40.0]
    ]];
    

提交回复
热议问题