1

亲爱的大家,自从过去 2-3 天以来,我一直在与 NSOutline View 进行斗争,以便在表格中执行拖放操作,但无法理解我做错了什么,这是我到目前为止所做的,

要求,1 - 我想在我的视图中有一个透明或带有一些背景图像的 NSoutlineview,为此,我需要覆盖 NSOutlineView 的 drawRect 方法,这就是我所做的

在头文件中

@interface MyCustomOutlineView:NSOutlineView{
NSImage *pBackgroundImage;

}

- setBackgroundImage:(NSImage *)pImage;

在源文件中,我只是覆盖 drawRect 和其他一些东西来绘制背景图像或使其透明,这工作正常,

现在在我看来,我已经像这样声明了 NSOutlineView 对象,

/* * 我的自定义视图将能够绘制渐变和其他效果
*/

@interface OutlineParentView:MyCustomView<NSOutlineDataSource>{
   MyCustomOutlineView *pOutlineView;
}

@property(nonatomic,retain)MyCustomOutlineView *pOutlineView;

在源文件中,实现了以下方法,该方法将从 initWIthFrame 中调用

#define OutlineViewPrivateDataType "MyOutlinePrivateData"
-(void)InitOutlineView{
    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];
    pOutlineView       = [[[CommUICustomOutlineView alloc] initWithFrame:clipViewBounds] autorelease];
    NSTableColumn*  firstColumn     = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
    ImageTextCell *pCell = [[ImageTextCell alloc]init];
    [firstColumn setDataCell:pCell];
    [pCell setDataDelegate:self];
    [firstColumn setWidth:25];
    [pOutlineView  addTableColumn:firstColumn];
    [pOutlineView setRowHeight:30];
    [pOutlineView setDataSource:self];

    /* setData delegate implemented in the MyOutlineView to handle some of event in this  
       interface if i don't write this, then i can't handle the menu event on the 
       Outlineview  
     */
    [pOutlineView setDataDelegate:self];

    **/* On this line i am getting one warning, saying OutlineParentView doesn't implement    
       NSOutlineView delegate protocol */**
    [pOutlineView setDelegate:self];
    [scrollView setDocumentView:pOutlineView];
    /* I don't want group row to be highlighted */
    [pOutlineView setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleSourceList];
    [pOutlineView registerForDraggedTypes:
         [NSArray arrayWithObjects:OutlineViewPrivateDataType,nil]];

    [pOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
    [scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
        [self addSubview:scrollView];
    [self setAutoresizesSubviews:YES];
    [self log:@"Outline view created "];

}

与拖放相关的其他重要方法实现如下

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteb oard:(NSPasteboard *)pboard{
    [self log:@"write Items"];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items];
    [pboard declareTypes:[NSArray arrayWithObject:OutlineViewPrivateDataType] 
    owner:self];
    [pboard setData:data forType:OutlineViewPrivateDataType];
    return YES;
}

    - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id < NSDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
    {
        NSLog(@"validate Drop");
        return NSDragOperationEvery;
    }
    - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id < NSDraggingInfo >)info item:(id)item childIndex:(NSInteger)index{
        [self log:@"inside accept drop for NSView "];
        return YES;
    }

我检查了苹果 DragnDrop 示例代码,但无法理解我做错了什么,我相信,有些问题

[pOutlineView setDelegate:self]

功能,但如何解决,我不知道,我最近从 MyTableView 升级到 MyOutlineView,最近我能够在自定义表视图上执行 Drag-nDrop,其余的东西工作正常,比如 DataSource 等......

在此先感谢 亲切的问候 Rohan

4

1 回答 1

1

我正在设置 ColumnWidth 所以拖放工作为已设置的宽度,而不是整行我的错误:(

 [firstColumn setWidth:25];

删除这条线工作正常

但是关于 NSoutlineView 和 WriteItem面临一些其他问题 的人 | 拖放问题

于 2011-02-04T11:14:51.423 回答