Static Cells 只能搭配 Table View Controller

當我們將 Table View 的 Content 欄位設為 Static Cells 時,我們可以方便地在 storyboard 設計表格內容,不用寫程式就能產生表格的每個 cell。

如下圖所示,我們利用 Static Cells 製作美麗的 App Store 列表,加入 3 個 cell 顯示三家分店。

雖然 Static Cells 很方便,不過它有個我們一定要牢牢記在心上的限制。

只有 Table View Controller 裡的 Table View 可以搭配 Static Cells !

如果我們使用 View Controller,然後在它的 view 上加入 Table View,這時候 Table View 是不支援 Static Cells 的。

此時 Xcode 的上方將顯示紅色錯誤,

錯誤訊息說

Static table views are only valid when embedded in UITableViewController instances

--

--

彼得潘的 iOS App Neverland
彼得潘的 Swift iOS App 開發問題解答集

彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,彼得潘的 Swift 程式設計入門,App程式設計入門作者,http://apppeterpan.strikingly.com