1

在我的应用程序中,NSOutlineView 使用如下, 1 - 使用 CustomOutlineView 因为我想控制 NSOutlineView 背景,

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 像素,我对此进行了评论,然后是它的工作时间,但奇怪的是,我的大纲视图只有一列,用于绘图,它不是检查限制,而是用于拖放它的检查,

谢谢约书亚

于 2011-02-04T08:38:45.150 回答