亲爱的, 我和NSOutline View一起战斗,从最近的2-3天开始在桌子内执行拖放操作,但无法得到我做错的事情, 这就是我到目前为止所做的,
要求, 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 "];
}
与Drag-n-Drop相关的其他重要方法如下所示
- (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,最近我能够在Custom Table视图上执行Drag-nDrop, 剩下的东西工作得很好,比如DataSource等......
先谢谢 亲切的问候 罗汉
答案 0 :(得分:1)
我正在设置ColumnWidth,因此拖放工作的宽度已设置,而不是在整行上我的错误:(
[firstColumn setWidth:25];
删除此行正常
但是面对其他问题的家伙们 Regarding NSoutlineView and WriteItem | Drag-and-Drop Problem