[上部分 链接
======][1]

上部分链接-同上方链接TableView里面 1 2 3 一样

#warning 移动 3 - 设置是否允许移动

  • (BOOL)tableView:(UITableView )tableView canMoveRowAtIndexPath:(NSIndexPath )indexPath
    {
    return YES;
    }

warning 移动 4 - 实现移动逻辑 实际移动结束时触发

  • (void)tableView:(UITableView )tableView moveRowAtIndexPath:(NSIndexPath )sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
    {

    NSLog(@"YIEM");
    
    

// 先操作数据
// 根据源坐标获取对象
NSString *sourceKey = [self.stuInfoDic.allKeys objectAtIndex:sourceIndexPath.section];
NSMutableArray *sourceArr = [self.stuInfoDic objectForKey:sourceKey];

// 得到要删除的学生对象 并且从数组中移除
// 注意引用计数!!!
Student *stu = [[sourceArr objectAtIndex:sourceIndexPath.row] retain];
[sourceArr removeObjectAtIndex:sourceIndexPath.row] ;
// 插入之前移除的学生对象
NSString *desKey = [self.stuInfoDic.allKeys objectAtIndex:destinationIndexPath.section];
NSMutableArray *desArr = [self.stuInfoDic objectForKey:desKey];
[desArr insertObject:stu atIndex:destinationIndexPath.row];

[stu release];
// 再操作界面

// [self.table moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];

}

warning 移动 5 - 限制跨区移动 (只能咋所在区域内进行移动)

  • (NSIndexPath )tableView:(UITableView )tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath )sourceIndexPath toProposedIndexPath:(NSIndexPath )proposedDestinationIndexPath
    {
    // 如果源区与目的区域不同 返回源区坐标 实现禁止跨区
    if (sourceIndexPath.section != proposedDestinationIndexPath.section) {

    return sourceIndexPath;

    }
    return proposedDestinationIndexPath;
    }

yiem
yiem
yiem
yiem