How do I add an UIView above a TableViewController

后端 未结 2 1808
暗喜
暗喜 2021-01-19 16:44

I would like to display an UIView above my tableview, for testing purposes I have used a Searchbar (to eliminate any possible problems with my code).

My setup:

2条回答
  •  春和景丽
    2021-01-19 17:03

    The really simple solution is to:

    • Create a custom UIViewController subclass that implements UITableViewDelegate and UITableViewDataSource just like UITableViewController does. Also add a UITableView outlet.
    • In the XIB file, put your searchbar and UITableView inside the view controller's view.
    • Connect the table view to the tableView outlet in your custom UIViewController
    • Connect the UITableView's delegate and datasource to the File's Owner (your custom UIViewController that implements the right delegates)

    You now have a custom view controller that works just like a UITableViewController except you have total control over it's layout. You implement the delegates in the same way.

提交回复
热议问题