// 设置 Cell的 编辑模式 : 删除 。 增加 ,None
#pragma mark -TableView delegate method
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==1) {
returnUITableViewCellEditingStyleInsert;
}else{
returnUITableViewCellEditingStyleDelete;
}
}
/**
* 2,设置当前视图控制器的"视图"编辑状态
* @param editing 是否设置当前控制器视图为可编辑
* @param animated 是否有动画效果
*
*/
//-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
// if (self.tableView.editing) {
// 为 self.tableView视图 调用 setEditing: 方法后,所有的cell都将触发编辑状态
// [self.tableView setEditing:NO animated:YES];
// }else{
// [self.tableView setEditing:YES animated:YES];
// }
//}
/**
* 设置 该 indexPath.row 是否可被编辑 ;
*/
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
if (indexPath.row==0) {
return NO;
}
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// delete row
if (editingStyle ==UITableViewCellEditingStyleDelete) {
// Delete the row from the data source :这行注释非常重要,说明了要在这应该做的操作:1,删除数据 2,移除行
[_fontsArrremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationTop];
}
// insert row
elseif (editingStyle ==UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
//同样上面的官方注释已经很清楚的说明了,要添加一行cell 要作的步骤:1,添加数据 2,插入行
NSString *newLine=@"New Line";
[_fontsArrinsertObject:newLine atIndex:indexPath.row+1];
NSIndexPath *newIndexPath=[NSIndexPathindexPathForRow:indexPath.row+1inSection:indexPath.section];
[tableView insertRowsAtIndexPaths:@[newIndexPath]withRowAnimation:UITableViewRowAnimationTop];
}
}
/**
* 对Cell 的移动设置
*/
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *testFromIndex=[[_fontsArrobjectAtIndex:fromIndexPath.row]retain];
[_fontsArrremoveObject:testFromIndex];
[_fontsArrinsertObject:testFromIndex atIndex:toIndexPath.row];
}
/**
* 对tableView cell进行有限制的移动设定;
*
*/
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
对于tableview 的编辑设置方法的分析: