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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM