NSCollectionView
안에 항목을 재배치하려고하는데 작동하지 않습니다. 일부 대리자 메서드는 validate drop
및 accept drop
으로 호출하지 않습니다. func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting?
또는 func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set<IndexPath>, to pasteboard: NSPasteboard) -> Bool
을 호출하지만 그 이후에는 다른 메소드를 호출하지 않습니다.Swift OSX - NSCollectionView를 드래그 앤 드롭으로 다시 정렬하지 마십시오.
제가 생각하기에 봇 (bot)은 드래그 앤 드롭을위한 올바른 유형을 등록 할 수 있다고 생각합니다. 컬렉션보기 내부의 항목을 이동할 때 항목을 삭제할 수있는 장소가 표시되지 않기 때문에 아이템을 원래 위치로 되 돌린다.
FotoProdutoLojaCollectionViewItem.swift 수입 코코아
class FotoProdutoLojaCollectionViewItem: NSCollectionViewItem {
@IBOutlet weak var fotoProdutoLojaImageView: NSImageView!
@IBOutlet weak var fotoCapaImageView: NSImageView!
override func viewDidLoad() {
super.viewDidLoad()
fotoCapaImageView.isHidden = true
}
}
여기 CollectionView
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
var item = NSCollectionViewItem()
item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "FotoProdutoLojaCollectionViewItem"), for: indexPath)
let fotosProdutoLojaCollectionViewItem = item as! FotoProdutoLojaCollectionViewItem
produtoLoja?.fotos[indexPath.item].foto?.getDataInBackground(block: {
(data: Data?, error: Error?) -> Void in
if error == nil {
fotosProdutoLojaCollectionViewItem.fotoProdutoLojaImageView.image = NSImage(data: data!)
}
})
if produtoLoja!.fotos[indexPath.item].imagemCapa {
fotosProdutoLojaCollectionViewItem.fotoCapaImageView.isHidden = false
}else {
fotosProdutoLojaCollectionViewItem.fotoCapaImageView.isHidden = true
}
return item
}
override func viewDidLoad() {
super.viewDidLoad()
fotosProdutoLojaCollectionView.delegate = self
fotosProdutoLojaCollectionView.dataSource = self
fotosProdutoLojaCollectionView.registerForDraggedTypes([NSPasteboard.PasteboardType(kUTTypeData as String)])
fotosProdutoLojaCollectionView.setDraggingSourceOperationMask(.move, forLocal: true)
}
의 상품 pasteboardWriterForItemAt indexPath
입니다 : 여기
func collectionView(_ collectionView: NSCollectionView, pasteboardWriterForItemAt indexPath: IndexPath) -> NSPasteboardWriting? {
let pb = NSPasteboardItem()
var data: Data?
do {
try data = produtoLoja?.fotos[indexPath.item].foto?.getData()
} catch {
}
pb.setData(data!, forType: NSPasteboard.PasteboardType.string)
return pb
//return NSPasteboardItem()
//return data as? NSPasteboardWriting
}
여기는 writeItemsAt indexPaths
입니다.
func collectionView(_ collectionView: NSCollectionView, writeItemsAt indexPaths: Set<IndexPath>, to pasteboard: NSPasteboard) -> Bool {
return true
}