您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 訊息 >> iOS 相關資訊

iOS UITableView 全面解析

編輯:iOS 相關資訊

UITableView 是 iOS 最常見的列表元件,支援分組與非分組樣式。

樣式與 Cell

UITableViewStylePlain 適合一般列表,UITableViewStyleGrouped 適合分組。Cell 內建 textLabel、detailTextLabel 與 imageView,可透過 UITableViewCellStyle 調整。

資料來源

表格需設定 dataSource 與 delegate。常用方法包括 numberOfSectionsInTableView、numberOfRowsInSection、cellForRowAtIndexPath、titleForHeaderInSection 與 titleForFooterInSection。

模型化資料

可將聯絡人與分組各自封裝成模型,例如 KCContact 與 KCContactGroup,再由表格讀取。這樣資料結構清楚,也方便日後擴充。

效能建議

大量資料時應使用 cell 重用機制,避免在滾動時頻繁建立物件。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved