在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在中间连接一下。

步骤如下:

先将 TableView 放到一个 UITableViewController 中,

然后在原来的 UITableViewController 加入一个 ContainerView,

最后连接 ContainerView 和 UITableViewController。


GitHub:https://github.com/backslash112/static-cells-uitableview-in-uiviewcontroller

你可能感兴趣的:(在UIViewController 中添加Static UITableView)