0

テーブルビューに 2 つのセクションがあり、1 つのセクションのみを更新する可変配列があります。セルを配列のあるセクションから空白のセクションに移動したいと思います。空白のセクション自体に別の配列を作成しようとしましたが、機能させることができませんでした。これが私の 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 が各セクションの適切な配列カウントを返しますが、まだ運がありません。編集モードに入ってセルを移動しようとすると、セルが消えます。

4

1 に答える 1

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];
于 2013-06-20T17:58:49.413 に答える