我希望編輯核心數據中的現有記錄。目前,我有這樣的代碼,但它會創建一個新的記錄(以及正確的數據插入到正確的列):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