dataSource
@property (nonatomic, weak, nullable) id <UITableViewDataSource> dataSource;
section&row
UITableView
@property (nonatomic, readonly) NSInteger numberOfSections;
- (NSInteger)numberOfRowsInSection:(NSInteger)section;
UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
cell
UITableView
UITableViewDataSource
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
注意:
- 不能返回nil,否则抛出异常
section index title
UITableView
UITableViewDataSource
- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView __TVOS_PROHIBITED; // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index __TVOS_PROHIBITED; // tell table which section corresponds to section title/index (e.g. "B",1))
注意:
- NSArray中的sectionIndexTitle与UITableView的section按照索引一一映射,NSArray元素数与UITableView section数可以不一致
- sectionForSectionIndexTitle重新映射NSArray中的sectionIndexTitle与UITableView的section,sectionForSectionIndexTitle点击section index list才触发
header title&footer title
UITableView
UITableViewDataSource
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; // fixed font style. use custom view (UILabel) if you want something different
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
注意:
- title字体风格固定,不能设置,如果delegate定制了header view&footer view,dataSource的header title&footer title设置ignored