親愛なる皆様、私は 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 "];
}
以下のように実装されたドラッグアンドドロップに関連するその他の重要なメソッド
- (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;
}
Apple DragnDrop のサンプル コードを確認しましたが、何が間違っているのかわかりませんでした。
[pOutlineView setDelegate:self]
機能ですが、それを解決する方法はわかりません。最近、MyTableView から MyOutlineView にアップグレードしました。最近、カスタム テーブル ビューでドラッグ アンド ドロップを実行できました。残りは、DataSource などのように正常に動作しています...
よろしくお願いしますローハン