0

coredata を使用して、テーブルビューに表示されるデータを配列に入力します。テーブルビューには、2 つのセクションがあります。セルがセクション 1 にプッシュされると、そのセルをセクション 2 に移動したり、その逆にしたりします。

これを達成する方法がよくわかりません。私はそれを理解しようとして約8時間座っていました.

これは私がこれまでに得たものです:

このコードを使用してデータを取得します。

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"creationDate" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];

NSMutableArray *sortedIngredients = [[NSMutableArray alloc] initWithArray:[event.tags allObjects]];
[sortedIngredients sortUsingDescriptors:sortDescriptors];
self.tagsArray = sortedIngredients;

[sortDescriptor release];
[sortDescriptors release];
[sortedIngredients release];

didSelectRowForIndexPath で、セルを削除する方法を見つけます。

Tag *tag = [tagsArray objectAtIndex:indexPath.row];

NSManagedObjectContext *context = event.managedObjectContext;
[context deleteObject:tag];

[tagsArray removeObject:tag];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

このセルをtableViewのセクション2に挿入するにはどうすればよいですか? 2 つのアレイを作成する必要がありますか? 次のように、NSDictionary を使用するコードをいくつか試しました。

[tableView addObject: sectionOneObject forKey:@"Section1"];
[tableView addObject: sectionTwoObjects forKey: @"Section2"]; 

しかし、私はそれを機能させることができません。

どんな助けでも大歓迎です!前もって感謝します

4

1 に答える 1

0

チェックアウト-insertRowsAtIndexPaths:withRowAnimation、例:

unsigned _insertionIndices[2] = {1,0}; // second section, first row
NSIndexPath *_insertionIndexPath = [[NSIndexPath alloc] initWithIndexes: _insertionIndices length:2];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:_insertionIndexPath] withRowAnimation: UITableViewRowAnimationRight];
[_insertionIndexPath release];
于 2009-09-27T22:20:47.760 に答える