且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 TableViewController 上方添加 UIView

更新时间:2023-11-17 13:40:34

真正简单的解决方案是:

The really simple solution is to:

  • 创建一个自定义的 UIViewController 子类,它实现了 UITableViewDelegateUITableViewDataSource,就像 UITableViewController 一样.还要添加一个 UITableView 插座.
  • 在 XIB 文件中,将您的搜索栏和 UITableView 放在视图控制器的视图中.
  • 将表格视图连接到自定义 UIViewController
  • 中的 tableView 插座
  • UITableView 的委托和数据源连接到文件的所有者(实现正确委托的自定义 UIViewController)
  • 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)

您现在拥有一个自定义视图控制器,它的工作方式与 UITableViewController 类似,但您可以完全控制它的布局.您以相同的方式实现委托.

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.