UITableView 总结

UITableView是UIScrollView的子类,因此它可以自动响应滚动事件(一般为上下滚动)。

它内部包含0到多个UITableViewCell对象,每个table cell展示各自的内容。当新cell需要被显示时,就会调用tableView:cellForRowAtIndexPath:方法来获取或创建一个cell;而不可视时,它又会被释放。由此可见,同一时间其实只需要存在一屏幕的cell对象即可,不需要为每一行创建一个cell。

1.协议介绍

UITableViewDataSource(11)


//每个section下cell的个数(必须实现)- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;//通过indexpath返回具体的cell(必须实现)- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;//返回有多少个section(默认是1)- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;//每个section上面的标语内容- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section;//每个section下面的标语内容- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section;// Editing//是否可编辑- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath;// Moving/reordering// 是否可拖拽-tableView:moveRowAtIndexPath:toIndexPath:

- (BOOL)tableView:(UITableView*)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath;// Index//右侧索引条需要的数组内容- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView;// return list of section titles to display in section index view (e.g. "ABCD...Z#")//索引值对应的section-index- (NSInteger)tableView:(UITableView*)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index;// tell table which section corresponds to section title/index (e.g. "B",1))// Data manipulation - insert and delete support// 对Cell编辑后的回调- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath;// 对Cell拖拽后的回调- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath;


未完待续

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容