2011-01-31 80 views
1

在我的應用程序,NSOutlineView用作以下, 1 - 使用CustomOutlineView因爲我想控制NSOutlineView背景,NSOutlineView拖N - 下降

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來調試,但我不能」 t看到上面的任何日誌功能, 我是否缺少任何重要的方法? 支持Drag-n-drop

+0

你*沒有* pos的代碼t正是我們需要看到的代碼。我們無法幫助您在發佈時修復拖放代碼。提示:writeRows ...方法是成功啓動拖動所需的最小值。 – 2011-01-31 12:19:25

+0

您好Joshua,我會上傳代碼,但是WriteRow也需要爲outlineView實現,因爲我看到了原型,它只爲TableView – Amitg2k12 2011-01-31 12:48:19

回答

1

根據你的代碼,它看起來像你沒有返回任何... writeItems ...方法。這個方法應該返回一個BOOL(無論項目是否成功寫入或者您拒絕拖動)。回到什麼應該給你一個編譯器警告......

0

HI, 終於得到了能夠擺脫這種, 問題是

[firstColumn setWidth:25]; 

所以拖了工作只有25高達像素形成左,和我評論這一點,那麼它的工作時間,但奇怪地看到,我的大綱視圖只有一列,用於繪圖,它不檢查的限制,但對拖正放棄其檢查,

感謝Joshua