UITableView 是 iOS 最常見的列表元件,支援分組與非分組樣式。
UITableViewStylePlain 適合一般列表,UITableViewStyleGrouped 適合分組。Cell 內建 textLabel、detailTextLabel 與 imageView,可透過 UITableViewCellStyle 調整。
表格需設定 dataSource 與 delegate。常用方法包括 numberOfSectionsInTableView、numberOfRowsInSection、cellForRowAtIndexPath、titleForHeaderInSection 與 titleForFooterInSection。
可將聯絡人與分組各自封裝成模型,例如 KCContact 與 KCContactGroup,再由表格讀取。這樣資料結構清楚,也方便日後擴充。
大量資料時應使用 cell 重用機制,避免在滾動時頻繁建立物件。