【IOS】UITableViewDataSource 常用API

@protocol UITableViewDataSource<NSObject>

@required

// 告诉数据源返回表视图的给定部分中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// 行显示, 实现人员应该“始终”尝试重用单元格,设置每个单元格的reuseIdentifier,并使用dequeueReusableCellWithIdentifier查询可用的可重用单元格
// 要求单元格的数据源插入表视图的特定位置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

@optional

// 要求数据源返回表视图中的节数。默认1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
// 向数据源询问表视图的指定部分的标题的标题。固定的字体样式。如果您想要一些不同的东西,可以使用custom view (UILabel)
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    
// 向数据源询问表视图的指定部分的页脚标题。
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// 单独的行可以选择不设置编辑属性。如果没有实现,则假定所有行都是可编辑的。
// 要求数据源验证给定行是否可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

// 移动/重新排序
// 允许可选地为特定行显示reorder附件视图。默认情况下,只有数据源实现-tableView:moveRowAtIndexPath:toIndexPath时,才会显示reorder控件
// 询问数据源是否可以将给定行移动到表视图中的另一个位置
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;

// 要求数据源返回表视图部分的标题。返回要在节索引视图中显示的节标题列表(例如。“ABCD…Z #”)
- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView; 
// 要求数据源返回具有给定标题和节标题索引的节的索引。
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;  

// 在一行调用减号或加号按钮之后(基于单元格的UITableViewCellEditingStyle),数据源必须提交更改
// 不调用编辑操作使用UITableViewRowAction -该操作的处理程序将被调用
// 要求数据源提交插入或删除接收器中的指定行。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

// 告知数据源将表视图中特定位置的行移动到另一个位置。
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;

@end
posted @ 2019-06-23 20:02  220和284  阅读(156)  评论(0编辑  收藏  举报