2

我的问题在于更新包含不同数量的 NSDictionary 的 NSMutableArray。每个 NSDictionary 有 6 个键,根据用户在表视图中选择的记录从数据库中检索这些键。该数组链接到一个允许用户选择字典并查看内容的 NSArrayController。

如果字典的 number[count] 个改变,arrayController 会更新视图;没问题。但是,表视图中的选择之间的字典计数相同,arrayController 不会更新视图,但模型会更新。

arrayController 在 IB 中绑定到模型数组,只要表格视图中的选择更改,该数组就会更新。

使用:

[self.selectedJobNotes addObject:[self.jobNotes objectAtIndex:i]];

这不符合 KVC。

但是使用(我认为它符合 KVC):

[[self.selectedJobNotes objectAtIndex:noteCount] setValue:[[self.jobNotes objectAtIndex:i]valueForKey:@“Content"] forKeyPath:@"Content"];

也不起作用。

有没有办法告诉 ArrayController 这是一个新数组/有新内容,所以重新加载。

[self.jobNotesArrayController fetch:self.a2gDataObject.selectedJobNotes];

好像也没用??!

4

1 回答 1

1

Best way to solve this is to implement (and use) indexed accessors. In your case they'd look like

- (void)insertObject:(NSDictionary *)dict inSelectedJobNotesAtIndex:(NSUInteger) index {
    [self.selectedJobNotes addObject:[self.jobNotes objectAtIndex:index]];
}


- (void)insertSelectedJobNotes:(NSArray *)notesArray atIndexes:(NSIndexSet *)indexSet {
    [self.selectedJobNotes insertObjects:notesArray atIndexes:indexSet];
}

See KVC Programming Guide: Mutable Indexed Accessors and Ensuring KVC Compliance.

You could also wrap your updates in willChange/didChange ValueForKey:, but implementing indexed accessors solves it once and for all.

于 2013-03-24T03:42:32.737 回答