NSOutline 视图拖放问题
各位, 自过去 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 "];
}
与 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,最近我能够在自定义表格视图上执行拖放, 剩下的事情工作正常,比如数据源等......
提前致谢 亲切的问候 罗汉
Dear All,
I am fighting with NSOutline View to perform drag-n-drop within the table since last 2-3 day but couldn't get what i am doing wrong,
This is what i have done so far,
Requirement,
1 -- I want to have a transparent or with some background image NSoutlineview in my view, to do that, i need to overwrite drawRect method of NSOutlineView, this is what i have done
in header file
@interface MyCustomOutlineView:NSOutlineView{
NSImage *pBackgroundImage;
}
- setBackgroundImage:(NSImage *)pImage;
In source file, i just overwrite drawRect and some other stuffs to draw the background image or to make it transparent and this is working fine,
Now in my view, i have declared the NSOutlineView object like that,
/*
* My Custom view will have capability to draw the gradient and other effects
*/
@interface OutlineParentView:MyCustomView<NSOutlineDataSource>{
MyCustomOutlineView *pOutlineView;
}
@property(nonatomic,retain)MyCustomOutlineView *pOutlineView;
In source file, implemented following method ,
This method will be called from the 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 "];
}
Other Important method related to Drag-n-Drop implemented as below
- (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;
}
I checked apple DragnDrop Sample code, but couldn't get what i am doing wrong,
i believe, some problem with the
[pOutlineView setDelegate:self]
Function, but how to solve that, that i don't know,
I upgraded recently from MyTableView to MyOutlineView, recently i was able to perform Drag-nDrop on the Custom Table view,
Remaining things are working fine, like DataSource etc...
Thanks in Advance
Kind Regards
Rohan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在设置 ColumnWidth ,因此拖放工作适用于已设置的宽度,而不是整行我的错误:(
删除此行工作正常
但人们面临其他问题
关于 NSoutlineView 和 WriteItem |拖放问题
i was setting ColumnWidth so drag-n-drop working for the width which has been set, not on the full row my mistake :(
Removing this line working fine
But guys facing some other problem
Regarding NSoutlineView and WriteItem | Drag-and-Drop Problem