How to add a UIView above the current UITableViewController

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

    Swift 2018

    Here is my way with storyboard:

    1) Add a view in storyboard.

    2) Link it with UITableViewController class:

    @IBOutlet weak var copyrightLabel: UILabel!
    

    3) Add it in code

    self.navigationController?.view.addSubview(copyrightView)
    copyrightView.frame = CGRect(x: 0,
                                y: self.view.bounds.size.height - copyrightView.bounds.size.height,
                                width: self.view.bounds.size.width,
                                height: copyrightView.bounds.size.height)
    

    4) Voilla!

    The view will not scroll with the table view. It can be easy designable from the storyboard.

    NOTE: This solution adds subview to the navigation controller and if you are going to another screen from here further down the nav, you will find this subview to persist, remove it using copyrightView.removeFromSuperView on viewDidDisappear while performing segue.

提交回复
热议问题