·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UITableViewDataSourceTableView數據源協議

UITableViewDataSourceTableView數據源協議

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

UITableViewDataSource TableView數據源協議
主要进行,数据的编辑(删除,插入),索引,移动排序的操作,是否允许编辑(删除,插入)和移动排序,设置显示的行数,组数,单元格的显示
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
返回的是一組數據有多少行
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
cell訪問數據源然後加載到tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;
返回有多少組,多少部分(默認是1,這個方法可以不實現)
-(NSString *)tableView:(UITableView *) titleForHeaderInSection:(NSInteger)section;
(固定的字體fixed font style,如果你想要不同的樣子,使用 custom view(UILabel))
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
控制行能否移動,return NO就不能执行排序操作了(比如移动按钮不会出现了)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;

控制能否编辑,如果return NO 不能执行编辑操作了(比如删除不会出现了)
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
要求的指定部分的表格视图的页眉标题数据源。
-(NSString *)tableVIew:(UITableView *)tableVIew titleForFooterInSection:(NSInteger)section;
要求的指定部分的表格视图的页脚标题数据源。
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView;
返回每组的标题,标题显示在索引视图中
-(Integer)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
返回分组的索引位置(在这个方法里面可以接收到索引的标题是什么,如果写成固定的值,那么点击索引不会对应的跳动了)
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
对特定的行进行删除跟插入的操作(editingStyle,编辑类型,可以通过他来区分是删除还是插入

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
对数据源将排在表视图中的一个特定的位置到另一个位置。(排序的操作用这个方法操作)