我希望编辑核心数据中的现有记录。目前,我有这样的代码,但它会创建一个新的记录(以及正确的数据插入到正确的列):NSManagedObject setValue问题(核心数据)
NSManagedObjectContext *context = [[NSApp delegate] managedObjectContext];
NSManagedObject *instrument = nil;
instrument = [NSEntityDescription insertNewObjectForEntityForName: @"Instrument"
inManagedObjectContext: context];
[instrument setValue:[NSNumber numberWithInt:quantityInStockInstruments]
forKey: @"quantity"];
结果将是这样的:
Instrument | Value | Quantity
Violin | £25 | 9
| | 8 <<< This is the new record that is created, instead of setting the
quantity of violin from '9' to '8'
我想编辑当前突出显示的行的数量列的程序(在本例中为“小提琴”行,我该怎么做?
如何更新当前突出显示的行取决于表如何获取其数据。你使用的是ArrayController /绑定还是数据源? – amrox 2009-11-05 20:45:10
我将表绑定到一个NSArrayController,实体是:instrument。仪器实体位于核心数据模型中。 顺便说一句,我实际上没有一个.h和.m文件对应于此NSArrayController。 – Michael 2009-11-05 21:06:39