一. 表视图的委托、源以及类绑定
1.设置表视图分区(组)的方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//一组
return 1;
}
2.设置表行数的方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//两行
return 2;
}
3.初始化行单元的方法(一般绑定数据源都写这个方法里面)
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//声明标识
static NSString *TableViewCellIndentifier = @"TableViewCellIndentifier ";
UITableViewCell *cell = [tableView dequeueReusableCellWithIndentifier:TableViewCellIndentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusIndentifier:TableViewCellIndentifier] autorelease];
}
//赋值操作
return cell;
}
4.当选中这行触发的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
5.当按下这行的详细箭头所触发的事件(一般会调用一个新的view)
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
}
6.确定表行编辑类型的方法
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;表示移动类型
return UITableViewCellEditingStyleDelete;表示删除类型
return UITableViewCellEditingStyleInsert;表示插入类型
//该方法只是定义类型 具体的实行要在具体方法中定义
}
7.移动操作方法
-(BOOL)table:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *) indexPaht{
return YES;
}
8.删除、插入方法的实现
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle) editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
}