我有一個關於使用KVO兼容方法從數組插入/刪除對象的問題。我工作過艾倫·希爾加斯可可規劃爲Mac OS X和我看到下面的代碼行(在insertObject:inEmployeesAtIndex:
方法:mutableArrayValueForKey和調用insertObject之間的區別:inEmployeesAtIndex:直接
[[undoManager prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];
糾正我,如果我錯了,但我一直認爲這是更好調用mutableArrayValueForKey:
然後removeObjectAtIndex:
...所以我試圖改變上述行來此:
[[undoManager prepareWithInvocationTarget:[self mutableArrayValueForKey:@"employees"]] removeObjectAtIndex:index];
而且它沒有工作一個人能解釋的區別,爲什麼第一線工作,但第二行沒有按」 t?
UP DATE:我的removeObjectFromEmployeesAtIndex:index方法被實現來使我的集合類(一個NSMutableArray的實例)符合KVC。所以最終,呼叫[[self mutableArrayValueForKey:@"employees"] removeObjectAtIndex:index];
應該最終打電話[self removeObjectFromEmployeesAtIndex:index];
哦,對不起,我感到困惑。我更新了一些更詳細的信息。但實際上,我確實想調用-removeObjecAtIndex:on [self mutableArrayValueForKey:@employees「] – jasonbogd 2010-06-30 02:35:12