在 TableView 中,Section 可把不同功能的儲存格分組顯示,例如 iOS 設定畫面。每個 Section 可有自己的標題、頁眉與頁腳。
除了 numberOfRowsInSection 與 cellForRowAtIndexPath,還可實作 numberOfSectionsInTableView 指定分區數量。若要顯示頁眉或頁腳,可實作 titleForHeaderInSection 與 titleForFooterInSection,並依 section 回傳不同文字。
完成後,列表會依分區顯示標題與說明,讓資訊層次更清楚。Section 很適合用在設定頁、分類列表或需要區塊標題的畫面。