2009-08-21 23 views
0

コードを追加した後にアプリケーションをビルドしていますが、Un-Recongnizedセレクタがインスタンスに送信されました。ここでエラーの写真です -インスタンスに送信されたセレクタが認識されない

alt text http://www.grabup.com/uploads/20f66eecee4bd96198c7bbcfe647ec74.png?direct

これはコードである私が追加(それはNSOutlineViewのデータソースのためです)

- (id)init 
{ 
    self = [super init]; 
    if (self != nil) { 
     // initialization code, rootsObjects is a NSArray instance variable 
     rootObjects = [NSArray arrayWithObjects:@"Joshua", @"Erne", nil]; 
    } 
    return self; 
} 

// here NSOutlineView asks how many children rows to display for a given item 
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item 
{ 
    // if item is nil this should be a Root row, else I pass 0 for example but should be the count of objects contained in item 
    return (item == nil) ? [rootObjects count] : 0; 
} 

// here NSOutlineView asks if a given item can be expanded i.e contains children 
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item 
{ 
    // again I return YES for example, but should be based on the count of objects contained in item 
    return YES; //(item == nil) ? YES : ([item numberOfChildren] != -1); 
} 

// here NSOutlineView asks for the object (some treelike structure) assigned to the nth index child row of item 
- (id)outlineView:(NSOutlineView *)outlineView 
      child:(int)index 
      ofItem:(id)item 
{ 
    // if item is nil I opass the appropriate Root row, else I pass nil for example but should be an object contained in item 
    return (item == nil) ? [rootObjects objectAtIndex:index] : nil; 
} 

// here NSOutlineView asks for the objectValue (usually a NSString)) to be displayed in tableColumn for the given item 
- (id)outlineView:(NSOutlineView *)outlineView 
objectValueForTableColumn:(NSTableColumn *)tableColumn 
      byItem:(id)item 
{ 
    // pass the object we want to display in the tableColumn for item 
    return item ; 
    // here I pass item for example since I know it's a NSString, but usually will be something to compute. 
    // the [tableColumn identifier] property (that can be set in Interface Builder) is very useful here. 
} 

// here NSOutlineView asks for the NSCell to be used by tableColumn for the given item 
- (NSCell *)outlineView:(NSOutlineView *)ov 
dataCellForTableColumn:(NSTableColumn *)tableColumn 
        item:(id)item 
{ 
    // the nil tableColumn represents the unified root row style 
    if (tableColumn == nil) { 
     // pass a cell we want to be used as root row (assume we've have assigned "Name" as identifier of some tableColumn) 
     return [[treeTable tableColumnWithIdentifier:@"Name"] dataCell]; 
    } 
    // else just pass the default cell 
    return [tableColumn dataCellForRow:[treeTable rowForItem:item]]; 
} 

- (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item { 
    return YES; 
} 

は、ここで私は(同じファイルを持っているコードですデータソース)を上記のコードとして使用します。

- (void)awakeFromNib { 

    dragType = [NSArray arrayWithObjects: @"factorialDragType", nil]; 

    [ dragType retain ]; 

    [ treeTable registerForDraggedTypes:dragType ]; 
    NSSortDescriptor* sortDesc = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES]; 
    [groupTreeControl setSortDescriptors:[NSArray arrayWithObject: sortDesc]]; 
    [ sortDesc release ]; 
} 


//------------------------------------ 
#pragma mark NSOutlineView datasource methods -- see NSOutlineViewDataSource 
//--------------------------------------------------------------------------- 
- (BOOL) outlineView : (NSOutlineView *) outlineView 
      writeItems : (NSArray*) items 
     toPasteboard : (NSPasteboard*) pboard { 

    [ pboard declareTypes:dragType owner:self ];   
    // items is an array of _NSArrayControllerTreeNode see http://theocacao.com/document.page/130 for more info 
    draggedNode = [ items objectAtIndex:0 ]; 

    return YES; 
} 




- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index { 

    _NSArrayControllerTreeNode* parentNode = item; 
    _NSArrayControllerTreeNode* siblingNode; 
    _NSControllerTreeProxy* proxy = [ groupTreeControl arrangedObjects ]; 

    NSManagedObject* draggedGroup = [ draggedNode observedObject ]; 

    BOOL draggingDown = NO; 
    BOOL isRootLevelDrag = NO; 

    // ---------------------- 
    // Setup comparison paths 
    // ------------------------- 
    NSIndexPath* draggedPath = [ draggedNode indexPath ]; 
    NSIndexPath* siblingPath = [ NSIndexPath indexPathWithIndex: index ]; 
    if (parentNode == NULL) {  
     isRootLevelDrag = YES; 
    } else { 
     // A non-root drag - the index value is relative to this parent's children 
     siblingPath = [ [ parentNode indexPath ] indexPathByAddingIndex: index ]; 
    } 

    // ---------------------- 
    // Compare paths - modify sibling path for down drags, exit for redundant drags 
    // -----------------------------------------------------------------------------  
    switch ([ draggedPath compare:siblingPath]) { 
     case NSOrderedAscending: // reset path for down dragging 
      if (isRootLevelDrag) { 
       siblingPath = [ NSIndexPath indexPathWithIndex: index - 1];        
      } else { 
       siblingPath = [ [ parentNode indexPath ] indexPathByAddingIndex: index - 1 ]; 
      } 
      draggingDown = YES; 
      break; 

     case NSOrderedSame: 
      return NO; 
      break;    
    } 

    siblingNode = [ proxy nodeAtIndexPath:siblingPath ];  

    // NSLog(@"returning early"); 
    // return NO; // TODO robustify 


    // ------------------------------------------------------------ 
    // SPECIAL CASE: Dragging to the bottom 
    // ------------------------------------------------------------ 
    // - K        - K       - C        - C 
    // - - U        - - C  OR  - U        - F 
    // - - C  ====>  - - F     - F        - K 
    // - - F    - U    - K        - U 
    // ------------------------------------------------------------ 
    if (isRootLevelDrag && siblingNode == NULL) {   
     draggingDown = YES; 
     siblingPath = [ NSIndexPath indexPathWithIndex: [ proxy count ] - 1 ];   
     siblingNode = [ proxy nodeAtIndexPath:siblingPath ] ; 
    } 

    // ------------------------------------------------------------ 
    // Give the dragged item a position relative to it's new sibling 
    // ------------------------------------------------------------ 
    NSManagedObject* sibling = [ siblingNode observedObject ]; 
    NSNumber* bystanderPosition = [ sibling valueForKey:@"position"]; 
    int newPos = (draggingDown ? [ bystanderPosition intValue ] + 1 : [ bystanderPosition intValue ] - 1); 
    [draggedGroup setValue:[ NSNumber numberWithInt:newPos ] forKey:@"position"]; 

    // ---------------------------------------------------------------------------------------------- 
    // Set the new parent for the dragged item, resort the position attributes and refresh the tree 
    // ----------------------------------------------------------------------------------------------  
    [ draggedGroup setValue:[ parentNode observedObject ] forKey:@"parent" ]; 
    [ self resortGroups:[draggedGroup managedObjectContext] forParent:[ parentNode observedObject ] ];   
    [ groupTreeControl rearrangeObjects ]; 
    return YES;    
} 






- (NSArray*) getSubGroups:(NSManagedObjectContext*)objectContext forParent:(NSManagedObject*)parent { 
    NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"projects" inManagedObjectContext:objectContext]; 

    [request setEntity:entity]; 
    NSSortDescriptor* aSortDesc = [[NSSortDescriptor alloc] initWithKey:@"position" ascending:YES]; 
    [request setSortDescriptors:[NSArray arrayWithObject: aSortDesc] ]; 
    [aSortDesc release]; 

    NSPredicate* validationPredicate = [NSPredicate predicateWithFormat:@"parent == %@", parent ]; 

    [ request setPredicate:validationPredicate ]; 

    NSError *error = nil; // TODO - check the error bozo 
    return [objectContext executeFetchRequest:request error:&error];  
} 




- (void) resortGroups:(NSManagedObjectContext*)objectContext forParent:(NSManagedObject*)parent { 

    NSArray *array = [ self getSubGroups:objectContext forParent:parent ]; 

    // Reset the indexes... 
    NSEnumerator *enumerator = [array objectEnumerator]; 
    NSManagedObject* anObject; 
    int index = 0; 
    while (anObject = [enumerator nextObject]) { 
     // Multiply index by 10 to make dragging code easier to implement ;) .... 
     [anObject setValue:[ NSNumber numberWithInt:(index * INTERVAL) ] forKey:@"position"];  
     index++; 
    } 


} 

- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index { 

    _NSArrayControllerTreeNode* newParent = item; 

    // drags to the root are always acceptable 
    if (newParent == NULL) { 
     return NSDragOperationGeneric; 
    } 

    // Verify that we are not dragging a parent to one of it's ancestors 
    // causes a parent loop where a group of nodes point to each other and disappear 
    // from the control 
    NSManagedObject* dragged = [ draggedNode observedObject ];  
    NSManagedObject* newP = [ newParent observedObject ]; 

    if ([ self category:dragged isSubCategoryOf:newP ]) { 
     return NO; 
    }  

    return NSDragOperationGeneric; 
} 

- (BOOL) category:(NSManagedObject*)cat isSubCategoryOf:(NSManagedObject*) possibleSub { 

    // Depends on your interpretation of subCategory .... 
    if (cat == possibleSub) { return YES; } 

    NSManagedObject* possSubParent = [possibleSub valueForKey:@"parent"]; 

    if (possSubParent == NULL) { return NO; } 

    while (possSubParent != NULL) {  
     if (possSubParent == cat) { return YES; } 

     // move up the tree 
     possSubParent = [possSubParent valueForKey:@"parent"];   
    } 

    return NO; 
} 

// This method gets called by the framework but the values from bindings are used instead 
+0

あなたが提供した情報が十分であるとは確信していません...スタックトレースも追加できますか? – fbrereto

+0

デバッガのエラーがスタックトレースを提供しませんでした。他にどのように私はそれを見つけるのですか? – Joshua

+0

デバッガコンソールで、 "b objc \ _exception \ _throw"と入力します(または、例外ウィンドウのRun-> Show-> Breakpointsを使用して例外を追加します)。デバッガがブレークしたら、デバッガウィンドウを開きます(実行 - >デバッガ)。左上のパネルにスタックトレースが表示されます。 stachトレースのどこかに-copyメッセージが表示されます。その下の最初の黒色のエントリは、問題を引き起こすコード内のポイントです。 –

答えて

1

エラーには、認識されないメソッドと送信された認識されないメソッドを受け取ったクラスの名前を指定する必要があります。

(1)メソッド名を認識した場合 - そのメソッドを呼び出すコードの行(または複数の行)を記述している場合は、コードの行を見直してメソッドのターゲットコールは有効であり、正しいタイプであり、他のどこかで公開されていません。

オブジェクトをどこかで余分に解放し、間違った型の新しいオブジェクトが古いオブジェクトのメモリに常駐すると、認識できないメソッド呼び出しエラーが発生することがよくあります。

(2)そのメソッドへの呼び出しを記述しなかった場合は、別のフレームワークメソッドにオブジェクトのタイプが間違っているか、何らかのフレームワークメソッドに何かが渡されました。

超過していると思われる場合は、NSZombiesを有効にするか、Instrumentsのゾンビトラッキング機能を使用してください(ええ、Peterさんの説明)。

したがって、エラーはNSTreeControllerTreeNode ... doesn't respond to -copyWithZone:です。

ほとんどの保証は、ツリーコントローラーツリーノードを辞書のどこかにキーとして押し込み、その辞書をコピーしようとしていることを示しています。少なくとも、それは最も一般的に何が起こるかです。

これは依然としてNSTreeControllerTreeNodeのインスタンスがNSStringが使用されていたメモリに座っているような場合には、リリース時の問題になる可能性があります。

現在のバージョンの開発ツールでXcodeを有効にする方法の詳細については、NSZombieを参照してください。

+0

No.2でなければならないと思います。 「パフォーマンスツールを使用して実行」メニューに移動すると、ゾンビオプションは表示されません。http://www.grabup.com/uploads/56e2b7a108333326d1acc6bfdde7d064.png?direct – Joshua

+0

ゾンビテンプレートがある可能性がありますXcodeのいくつかの仮想的な将来のバージョンですが、3.1.3にはありません。 ☺ –

+0

私が気付いたことは、最初の質問からコードを取り除くと、問題なくアプリが正常に動作することです。ですから、問題はそのコードのどこかでなければなりません。 – Joshua

0

NSTreeControllerTreeNodeは標準のココアクラスではありません。

代わりにNSTreeControllerまたはNSTreeNodeを使用しましたか?

+0

それは事です、私は実際にそれを使用していません。私が気づいたのは、コード(最初の投稿のコード)を取り除くと、アプリケーションは問題なく走ったので、問題は最初の投稿のコードになければならないということでした。私はNSTreeControllerTreeNodeを使用していません。 – Joshua

+0

「最初の投稿のコード」とはどういう意味ですか? – Abizern

+0

私が意味したのは、質問にあるコードです。 – Joshua

関連する問題