2011-01-29 60 views
1

我有以下代碼來支持將應用程序文件拖放到表視圖中。問題是,當我拖放時,我甚至沒有看到綠色+。我認爲這與registerForDraggedTypes:有關,但我不確定。我已經嘗試了很多教程,但都沒有爲我工作。NSTableView拖放應用程序文件,出什麼錯了?

- (void)awakeFromNib { 
[apps registerForDraggedTypes:[NSArray arrayWithObject:@"app"]];  
} 


- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes   toPasteboard:(NSPasteboard*)pboard 
{ 
return YES; 
} 
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op 
{ 
return NSDragOperationCopy; 
} 

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info 
      row:(int)row dropOperation:(NSTableViewDropOperation)operation 
{ 
return YES; 
} 

預先感謝

回答

1

registerForDraggedTypes不是找文件擴展名的陣列;它需要一個數組uniform type indentifiers。如果你想接受的文件名,使用NSFilenamesPboardType

[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]]; 

然後,只接受.app文件,檢查擴展和tableView:acceptDrop:row:dropOperation:返回YES,漸漸從NSDraggingInfo and its pasteboard適當的信息。

+0

出於某種原因,我仍然沒有看到綠色+。什麼可能導致這個? – nosedive25 2011-01-29 22:01:46