父母的孩子关系 - 我的父母知道它的孩子,但孩子们应该知道父母的时间

时间:2013-06-09 19:40:44

标签: objective-c cocoa parent

我正在开发一个具有书籍对象(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

0 个答案:

没有答案