First off: I have read questions related to this problem a few times on here and I am posting this with the awareness that people might consider this a duplicate question. But I have to say that as a beginner I have not found any helpful information, so I with this question I hope to make things very clear for me as well as others.
How I understand Bindings & KVC / KVO
Consider this: I have an array (in my AppDelegate), an ArrayController and a view element, say, NSTableView. I have bound the NSMutableArray in my AppDelegate to the ArrayController, which in turn is bound to the NSTableView.
Changing some object's property in the NSTableView leads to an actual change in that object's property. So far it works. However, changing something in the NSMutableArray (e.g. adding an item) does not update NSTableView.
Possible solutions I have read about
I have read multiple answers now. One answer seemed to suggest that I should not add anything to the array itself, but only to the ArrayController. I am not sure if this is correct, but if this is a possible solution it would be great to get a few more details on how to do this.
Other solutions mention the following methods:
- valueForKey:
- valueForKeyPath:
- dictionaryWithValuesForKeys:
- valueForUndefinedKey:
- mutableArrayValueForKey:
Especially:
- mutableArrayValueForKey:
How do I use mutableArrayValueforKey?
What I do not know however is how to use any of these methods with my array / within my application. The mutableArrayValueForKey method returns an NSMutableArray. Do I have to create a new array with this?
Right now, what I am doing is this.
self.vocabList = [[NSMutableArray alloc] init];
and later on, in a method, I am filling the array:
for (NSObject* o in meaningsArray)
{
NSLog(@"%@",o);
Vocab *temp = [[Vocab alloc] init];
[temp setValue:@"w" forKey:@"word"];
[temp setValue:@"m" forKey:@"meaning"];
[self.vocabList insertObject:temp atIndex:[self.vocabList count]];
}
If everything I have said is correct so far, my question is: Where would mutableArrayValueForKey: come into the picture when wanting to update the NSTabeleView? Or did I misunderstand something in the first place?