1

私のアプリケーションでは、NSOutlineViewは次のように使用されます。1-NSOutlineViewの背景を制御したいので、CustomOutlineViewを使用します。

2--CustomeCellを使用して、Cellをカスタマイズする必要があるため

ヘッダーファイル:MyListView.h

/* 
 MyUICustomView is the Subclass from NSView and this is i need to have 
 for some other my application purpose 
*/
@interface MyListView : MyUICustomView<NSOutlineViewDataSource> 
{
      // MyCustomOutlineview because, i need to override DrawRect Method to have   
      //   customized background 
      MyCustomOutlineView *pMyOutlineView;

}

@property(nonatomic,retain)MyCustomOutlineView *pMyOutlineView;

また、アウトラインビュー内でドラッグアンドドロップできるはずです。ドラッグアンドドロップを行ったのは、次のとおりです。

  -(void)InitOutlineView{
        // Creating outline view 
        NSRect          scrollFrame = [self bounds];
    NSScrollView*   scrollView  = [[[NSScrollView alloc] initWithFrame:scrollFrame] autorelease];

    [scrollView setBorderType:NSNoBorder];
    [scrollView setHasVerticalScroller:YES];
    [scrollView setHasHorizontalScroller:NO];
    [scrollView setAutohidesScrollers:YES];
    [scrollView setDrawsBackground: NO];

    NSRect          clipViewBounds  = [[scrollView contentView] bounds];
    pMyOutlineView       = [[[MyCustomOutlineView alloc] initWithFrame:clipViewBounds] autorelease];


    NSTableColumn*  firstColumn     = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
#ifdef ENABLE_CUSTOM_CELL
        // Becuase cell should have Image, Header Info and brief detail in small font, 
        // so i need to have custom cell 
    ImageTextCell *pCell = [[ImageTextCell alloc]init];
    [firstColumn setDataCell:pCell];
        // SO i can fill the data 
    [pCell setDataDelegate:self];
# endif

        [pMyOutlineView setDataSource:self];
        /* This is to tell MyCustomOutlineView to handle the context menu */
    [pMyOutlineView setDataDelegate:self];
        [scrollView setDocumentView:pCTOutlineView];

        [pMyOutlineView  addTableColumn:firstColumn];
        [pMyOutlineView registerForDraggedTypes:
         [NSArray arrayWithObjects:OutlinePrivateTableViewDataType,nil]];

        [pMyOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];**

    }

およびドラッグアンドドロップをサポートするために次の方法を実装しました

        - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard{
        NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items];
        [pboard declareTypes:[NSArray arrayWithObject:OutlinePrivateTableViewDataType] owner:self];
        [pboard setData:data forType:OutlinePrivateTableViewDataType];
        return YES;

    }


    - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index{
    // Add code here to validate the drop

    NSLog(@"validate Drop");
    return NSDragOperationEvery;
}

        - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index{
          NSLog(@"validate Drop");
    }

しかし、NSOutlineViewの行をドラッグしようとすると、何も起こりません。NSLogを介してデバッグしようとしても、上記の関数からログが表示されませんでした。重要なメソッドがありませんか?ドラッグアンドドロップをサポートする

4

2 に答える 2

1

コードに基づいて、 ...writeItems... メソッドに対して何も返していないようです。このメソッドは、BOOL を返すことになっています (項目が正常に書き込まれたか、ドラッグを拒否しているかに関係なく)。何も返さないと、コンパイラの警告が表示されるはずです...

于 2011-01-31T15:04:51.667 に答える
0

こんにちは、ようやくこれを取り除くことができました、問題は

[firstColumn setWidth:25];

したがって、ドラッグは左側から最大 25 ピクセルまでしか機能していませんでした。これについてコメントしましたが、その作業時間ですが、奇妙なことに、私のアウトライン ビューには 1 つの列しかありません。そのチェック、

ありがとうジョシュア

于 2011-02-04T08:38:45.150 に答える