Uitableview 将行移动到不同的部分

Uitableview 将行移动到不同的部分,uitableview,nsmutablearray,tableview,Uitableview,Nsmutablearray,Tableview,嘿,伙计们,我的tableview上有两个部分,我有一个可变数组,只更新一个部分。我想把数组中的单元格移到空白部分。我试着为空白部分创建另一个数组,但我不能让它工作。这是我的moveRowAtIndexPath方法 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { id object

嘿,伙计们,我的tableview上有两个部分,我有一个可变数组,只更新一个部分。我想把数组中的单元格移到空白部分。我试着为空白部分创建另一个数组,但我不能让它工作。这是我的moveRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{

id objectToMove = [myArray1 objectAtIndex:fromIndexPath.row];
id objectToMove2 = [myArray2 objectAtIndex:fromIndexPath.row];

//move objects between main section
[myArray1 removeObjectAtIndex:fromIndexPath.row];
[myArray1 insertObject:objectToMove atIndex:toIndexPath.row];


//move object from main section to blank section
 [myArray1 removeObjectAtIndex:fromIndexPath.row];
 [myArray2 insertObject:objectToMove atIndex:toIndexPath.row];

我让numberOfRowsInSection返回每个节的相应数组计数,但仍然不走运。当我进入编辑模式并尝试移动单元格时,它会消失。

用此代码修复了它

NSString * cell = nil;
switch (fromIndexPath.section) {
    case 0:
        cell = [[myArray2 objectAtIndex:fromIndexPath.row] retain];
        [myArray2 removeObjectAtIndex:fromIndexPath.row];
        break;
    case 1:
        cell = [[myArray1 objectAtIndex:fromIndexPath.row] retain];
        [myArray1 removeObjectAtIndex:fromIndexPath.row];
        break;
    }

switch (destinationIndexPath.section) {
    case 0:
        [myArray2 insertObject:cell atIndex:destinationIndexPath.row];
        break;
    case 1:
        [myArray1 insertObject:cell atIndex:destinationIndexPath.row];
        break;

}

[cell release];