2013-07-11 23 views
5

Có cần thiết phải phân lớp NSTableView hoặc NSTableCellView để tạo hình ảnh kéo tùy chỉnh khi tableView là nguồn kéo không?Kéo hình ảnh tùy chỉnh bằng NSTableView dưới dạng nguồn kéo

Nếu không, phương pháp ma thuật mà tôi thiếu để làm điều này là gì? Tôi dường như không thể tìm thấy thứ gì chắc chắn.

NSTableCellView lớp con có thể (hơi một cách bí ẩn) override:

@property(retain, readonly) NSArray *draggingImageComponents (mảng của NSDraggingImageComponent trường hợp đó sẽ được ghép lại với nhau (người hiểu biết những gì họ nhận được thời trang ghép ...))

NSTableView chính nó có

- (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset

Nhưng đây thực sự là các tùy chọn phân lớp.

Có ai biết kỹ thuật khác ở đây không? (10.8+ là mục tiêu)

+0

Trong thử nghiệm tiếp tục bắt đầu với NSTableCellView đầu tiên (đường dẫn của ít nhất kháng!) Có vẻ như rằng mặc dù họ cung cấp một hình ảnh, nó lần đầu tiên đi qua xem bảng, và xem bảng hiện một số weirdness để kéo hình ảnh dựa trên nó xem clip ... mọi thứ không hiển thị trong chế độ xem clip khi kéo bắt đầu không phải là một phần của hình ảnh kéo. – uchuugaka

Trả lời

0

Trong data source bạn sẽ muốn đặt hình ảnh, ví dụ: từ phương pháp tableView:draggingSession:willBeginAtPoint:forRowIndexes: của bạn như vậy

[session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent 
             forView:tableView 
             classes:[NSArray arrayWithObject:[NSPasteboardItem class]] 
           searchOptions:nil 
            usingBlock:^(NSDraggingItem *draggingItem, NSInteger index, BOOL *stop) 
    { 
     [draggingItem setDraggingFrame:NSMakeRect(0, 0, myWidth, myHeight) 
          contents:myFunkyDragImage]; 
    }]; 
4

Có vẻ như nếu NSTableViewCell

@property(retain, readonly) NSArray *draggingImageComponents 

không được gọi là tự động nhưng phải được tham chiếu rõ ràng cho quan điểm bảng dựa xem. -draggingImageComponents có thể được ghi đè để cung cấp các thành phần được sử dụng để tổng hợp hình ảnh kéo.

- (void)tableView:(NSTableView *)tableView draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint forRowIndexes:(NSIndexSet *)rowIndexes 
{ 
    // configure the drag image 
    // we are only dragging one item - changes will be required to handle multiple drag items 
    BPPopupButtonTableCellView *cellView = [self.columnsTableView viewAtColumn:0 row:rowIndexes.firstIndex makeIfNecessary:NO]; 
    if (cellView) { 

     [session enumerateDraggingItemsWithOptions:NSDraggingItemEnumerationConcurrent 
              forView:tableView 
              classes:[NSArray arrayWithObject:[NSPasteboardItem class]] 
            searchOptions:nil 
             usingBlock:^(NSDraggingItem *draggingItem, NSInteger idx, BOOL *stop) 
     { 
      // we can set the drag image directly 
      //[draggingItem setDraggingFrame:NSMakeRect(0, 0, myWidth, myHeight) contents:myFunkyDragImage]; 

      // the tableview will grab the entire table cell view bounds as its image by default. 
      // we can override NSTableCellView -draggingImageComponents 
      // which defaults to only including the image and text fields 
      draggingItem.imageComponentsProvider = ^NSArray*(void) { return cellView.draggingImageComponents;}; 
     }]; 
    } 
} 
Các vấn đề liên quan