從 iOS 15 開始,使用內建 cell 樣式建議搭配 UIListContentConfiguration

彼得潘的 iOS App Neverland
2 min readAug 7, 2021

當我們在 Xcode 13 存取 UITableViewCell 的 textLabel,detailTextLabel & imageView 時,Xcode 警告我們,textLabel will be deprecated in a future version of IOS. Use UIListContentConfiguration instead, this property will be deprecated in a future release.

官方文件也提到, textLabel,detailTextLabel & imageView 的 Availability 是 iOS 3 ~ 14。(ps: 雖然 deprecated,不過目前在 iOS 15 還是可以正常使用)

從 iOS 15 開始,使用內建 cell 樣式時 Apple 建議我們搭配 iOS 14 推出的 UIListContentConfiguration,比方以下例子:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
var content = cell.defaultContentConfiguration()
content.image = UIImage(systemName: "star")
content.text = "小星星"
content.secondaryText = "一閃一閃亮晶晶"
cell.contentConfiguration = content
return cell
}

Apple 官方範例

Develop in Swift Data Collections。

1.5 Table Views 的 Emoji Dictionary。

1.5 Lab Meal Tracker。

範例下載。

UIListContentConfiguration 說明

--

--

彼得潘的 iOS App Neverland

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