我正在开发一个具有书籍对象(RSEBook)的应用程序,每个书籍对象都有一个关键字对象的NSMutableArray(关键字)。书中的可变数组称为'关键字'
将子项(关键字)添加到父数组的方法是:
- (void)addTag :(关键字*)字 {
[keywords addObject:word];
[word setParent:self];
}
但是,当在Document.m中调用它时:
- (IBAction为)createKeyword:(ID)发送方{
NSWindow * w = [tabView窗口];
BOOL editingEnded = [w makeFirstResponder:w]; if(!editingEnded) { NSBeep(); return; } Keyword *k = [[Keyword alloc] init]; //Create a new keyword instance id current = [booksAC selectedObjects]; //NSArray of the selectedObjects (there will only ever be one object in the array as my table view hasn't got multi selection RSEBook *currBook = [current objectAtIndex:0]; //Get that object into currBook if (!currBook) { //Check that currBook = something NSLog(@"current is nil"); }
[currBook addTag:k]; //Add the object k as a tag to currBooks NSMutableArray 'keywords' this SHOULD set the parent, but it dosent (defined in RSEBook.h)
NSLog(@"The keywords parent: %@" ,[k parent]); // this is always null for some reason
NSLog(@"parents keywords: %@", [currBook keywords]); // this returns what I expect, a list of the books keywords