UITableView的结构

UITableVIew包含多个UITableVIewCell,而UITableVIewCell中有可以添加各种UI控件;cell的排布用section和row来表示,还可以在代码中添加header和fonter首尾标识行。一个UITableView要可以实现datasource和delegate两种方法,其中datasource中的三个方法必须实现:
Section个数:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
每个Section中row个数:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
以及定义每个cell的内容:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return cell;
}
编辑模式
不提供方法则默认为delete:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
默认所有行可编辑:
- (BOOL)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
提供该方法,就会打开左划编辑手势在这里响应删除/新建操作:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
提供该方法,编辑态就会显示移动控件在这里响应移动操作:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)indexPath
网友评论