2013-06-20 41 views
0

嘿家伙我在我的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返回适当的数组计数为每个部分,但仍然没有运气。当我进入编辑模式时,我尝试移动单元格消失。

回答

0

修正了这个问题。

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]; 
相关问题