iOS: 在UIViewController 中添加Static UITableView

如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错:
Static table views are only valid when embedded in UITableViewController instances.
 
 
意思是说,如果 UITableView 不是在 UITableViewController 而是在 UIViewController 中的时候,是不允许将 UITableView 的 Content 属性设置为 Static Cells 的。
 
但是,如果想让 UIViewController 中的 UITableView 是一个 Static Cells 的怎么办呢?
 
方法是有的!既使用Container View在中间连接一下。
步骤如下:
  1. 先将 TableView 放到一个 UITableViewController 中,
  2. 然后在原来的 UITableViewController 加入一个 ContainerView,
  3. 最后连接 ContainerView 和 UITableViewController。
 

效果:

 


相关源代码:GitHub

原文地址:https://www.cnblogs.com/sirkevin/p/4190114.html