2013-07-11 13 views
5

Czy konieczne jest utworzenie podklasy NSTableView lub NSTableCellView w celu utworzenia niestandardowego obrazu przeciągania, gdy tableView jest źródłem przeciągania?Niestandardowy obraz przeciągania z NSTableView jako źródłem przeciągania

Jeśli nie, jaka jest magiczna metoda, której mi brakuje, aby to zrobić? Nie mogę znaleźć niczego solidnego.

NSTableCellView podklasy mają może (nieco tajemniczo) przesłanianie:

@property(retain, readonly) NSArray *draggingImageComponents (tablica NSDraggingImageComponent przypadki, że dostanie połączone razem (kto wie, w jaki moda dostają komponowane ...))

NSTableView sam ma

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

Ale to są rzeczywiście opcje podklasy.

Ktoś zna inną technikę tutaj? (10.8+ jest celem)

+0

W dalszym badaniom zaczynając NSTableCellView pierwszej (ścieżki najmniejszego oporu!) Wydaje się, że choć stanowią one obraz, najpierw przechodzi przez widoku tabeli, a widok tabeli ma jakiś niesamowitość przeciągać obrazy na podstawie jego widok klipu ... wszystko, co nie jest widoczne w widoku klipu, gdy rozpoczyna się przeciąganie, nie jest częścią obrazu przeciągania. – uchuugaka

Odpowiedz

0

W swoim data source będziesz chciał ustawić obrazy np. od sposobu tableView:draggingSession:willBeginAtPoint:forRowIndexes: jak tak

[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

Wygląda jakby NSTableViewCell

@property(retain, readonly) NSArray *draggingImageComponents 

nie nazywa się automatycznie, ale musi być wyraźnie odwołuje się do poglądów opartych Table View. -draggingImageComponents można przesłonić, aby dostarczyć komponenty użyte do złożenia obrazu przeciągania.

- (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;}; 
     }]; 
    } 
} 
Powiązane problemy