首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSOutlineView拖放

NSOutlineView拖放
EN

Stack Overflow用户
提问于 2011-01-31 19:00:33
回答 2查看 2K关注 0票数 1

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

2 --使用CustomeCell,因为我需要自定义单元格

头文件: MyListView.h

代码语言:javascript
复制
/* 
 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;

我还应该能够在大纲视图中拖放,因为我已经完成了下面的拖放操作。

代码语言:javascript
复制
  -(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];**

    }

并支持实现如下方法的拖放

代码语言:javascript
复制
        - (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进行调试,但是我看不到上述函数的任何日志,我是否遗漏了任何重要的方法?支持拖放

EN

回答 2

Stack Overflow用户

发布于 2011-01-31 23:04:52

根据您的代码,看起来您没有为...writeItems返回任何内容...方法。此方法应返回一个BOOL (无论项目是否已成功写入或您是否拒绝拖动)。什么都不返回应该会给你一个编译器警告...

票数 1
EN

Stack Overflow用户

发布于 2011-02-04 16:38:45

嗨,FInally解决了这个问题,问题是

代码语言:javascript
复制
[firstColumn setWidth:25];

所以拖拽只工作到25个像素的左边,我注释了这个,然后它的工作时间,但奇怪的是,我的大纲视图只有一列,用于绘图,它不检查限制而是拖放它的检查,

谢谢Joshua

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4850087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档