Ich versuche, ein Drag & Drop-System basierend auf einer Tabelle von Zellen (Indizes von 1 bis 17) zu erstellen, die mit einem NSAmage-Array verbunden wird, das je nach dem Ziehen geändert wird und Ergebnis fallen lassen. Mein Tisch scheint zu ziehen (die Zahl mit ein wenig Transparenz ist beweglich), aber nichts passiert, wenn ich ablege. Ich vermute, dass etwas mit meiner Typregistrierung nicht stimmt, aber ich bin ein bisschen neu bei osx. Kann jemand helfen?Drag & Drop auf eine Zeichenfolge/Bilder NSTableView Swift
var images:[NSImage] = []
func getImages() {
images = []
for i in 50...66 {
images.append(NSImage(named: "IMG_67\(i)")!)
}
}
func tableViewSelectionDidChange(notification: NSNotification) {
let table = notification.object
let selection = table?.selectedRow
imgView.image = images[selection!]
}
func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
tableView.cell?.title = String(row)
return row + 1
}
func numberOfRowsInTableView(tableView: NSTableView) -> Int {
getImages()
return images.count
}
func tableView(tableView: NSTableView, writeRowsWithIndexes rowIndexes: NSIndexSet, toPasteboard pboard: NSPasteboard) -> Bool {
let data:NSData = NSKeyedArchiver.archivedDataWithRootObject(rowIndexes)
let registeredTypes:[String] = [NSGeneralPboard] //Problem might be here
pboard.declareTypes(registeredTypes, owner: self)
pboard.setData(data, forType: NSGeneralPboard)
return true
}
func tableView(tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableViewDropOperation) -> NSDragOperation {
if dropOperation == .Above {
return .Move
}
return .All
}
func tableView(tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableViewDropOperation) -> Bool {
let data: NSData = info.draggingPasteboard().dataForType(NSGeneralPboard)!
let rowIndexes: NSIndexSet = NSKeyedUnarchiver.unarchiveObjectWithData(data) as! NSIndexSet
let value: NSImage = images[rowIndexes.firstIndex]
images.removeAtIndex(rowIndexes.firstIndex)
if (row > images.count)
{
images.insert(value, atIndex: row - 1)
} else {
images.insert(value, atIndex: row)
}
tableView.reloadData()
print("returning true") //Not getting called at all
return true
}
Kennen Sie das Äquivalent zu Swift 4? –