2013-06-20 2 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]; 

각 섹션에 대해 적절한 배열 수를 반환하지만 number 행을 반환하는 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]; 
관련 문제