0

私は書籍オブジェクト (RSEBook) を持つアプリに取り組んでおり、それぞれにキーワード オブジェクト (Keyword) の NSMutableArray があります。本の可変配列は「キーワード」と呼ばれます

親の配列に子 (キーワード) を追加する方法は次のとおりです。

-(void)addTag:(キーワード *)単語 {

[キーワード addObject:単語];

[word setParent:self];

}

ただし、これが Document.m で呼び出されると、次のようになります。

-(IBAction)createKeyword:(id)送信者{

NSWindow *w = [タブ ビュー ウィンドウ];

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
4

0 に答える 0