表视图的编辑模式
表视图的编辑模式有三种,添加、删除和移动
表视图的编辑模式流程
核心代码
//新增、删除按钮事件
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
//删除
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_data removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
//新增
else if (editingStyle == UITableViewCellEditingStyleInsert) {
NSString *obj = [NSString stringWithFormat:@"我是新添加的"];
[_data insertObject:obj atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
表视图的编辑模式有三种,添加、删除和移动
表视图的编辑模式流程
核心代码
//新增、删除按钮事件
- (void)tableView:(UITableView *)tableView commitEditingStyle:
(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
//删除
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_data removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
//新增
else if (editingStyle == UITableViewCellEditingStyleInsert) {
NSString *obj = [NSString stringWithFormat:@"我是新添加的"];
[_data insertObject:obj atIndex:indexPath.row];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}