在我的应用程序中,NSOutlineView的用法如下:1 --使用CustomOutlineView因为我想控制NSOutlineView背景,
2 --使用CustomeCell,因为我需要自定义单元格
头文件: 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进行调试,但是我看不到上述函数的任何日志,我是否遗漏了任何重要的方法?支持拖放
发布于 2011-01-31 23:04:52
根据您的代码,看起来您没有为...writeItems返回任何内容...方法。此方法应返回一个BOOL (无论项目是否已成功写入或您是否拒绝拖动)。什么都不返回应该会给你一个编译器警告...
发布于 2011-02-04 16:38:45
嗨,FInally解决了这个问题,问题是
[firstColumn setWidth:25];所以拖拽只工作到25个像素的左边,我注释了这个,然后它的工作时间,但奇怪的是,我的大纲视图只有一列,用于绘图,它不检查限制而是拖放它的检查,
谢谢Joshua
https://stackoverflow.com/questions/4850087
复制相似问题