フェッチされたデータとバスケットボタンを持つカスタムtableViewCellがあります。セルのバスケットをクリックして別のエンティティ(バスケットエンティティ)に保存するにはどうすればいいですか?CoreDataに選択したカスタムTableViewCellを保存する
- (IBAction)basketButton:(id)sender
{
NSManagedObjectContext *context = [app managedObjectContext];
UIButton *button = sender;
NSInteger rowInIndexPath =button.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowInIndexPath inSection:0];
Basket *basket = [NSEntityDescription insertNewObjectForEntityForName:@"Basket" inManagedObjectContext:context];
//missing code
NSError *error;
if (![context save:&error])
{
NSLog(@"fail : %@", [error localizedDescription]);
}
}
私のソリューション:
私は私の機能セルの位置を伝えるのを忘れていました。
- (IBAction)basketButton:(id)sender {
NSManagedObjectContext *context = [app managedObjectContext];
UIButton *button = sender;
NSInteger rowInIndexPath =button.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowInIndexPath inSection:0];
Basket *basket = [NSEntityDescription insertNewObjectForEntityForName:@"Basket" inManagedObjectContext:context];
Product *product = [self.fetchedResultsController objectAtIndexPath:indexPath];
basket.productname =product.productname ;
NSError *error;
if (![context save:&error])
{
NSLog(@"fail : %@", [error localizedDescription]);
}
}
私はパリモンドと同意する必要がありますが、私はそれがあなたが何を保存したいのか、そしてどこに行きたいのかは分かりません。私はここに仕事の言語障壁があると思う。おそらくあなたのデータモデルとあなたのデータについて私たちに教えてもらえますか? – QED
が動作します。とにかくありがとう –
@ErayGeveciあなた自身の答えを投稿してください。将来的に誰かにとって役に立ちます。このサイトはコミュニティの取り組みであることを覚えておいてください。 – Palimondo