如何解决NSCollectionView DidSelectItemsAt 无效
当 NSCollectionViewItem 添加 mouseDown 时,DidSelectItemsAt 不再起作用。
我是不是做错了什么?
我是新手。希望有好心人帮帮我
================================================ ====================
class ViewController: NSViewController {
@IBOutlet weak var collextionView: NSCollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collextionView.register(cell_item.self,forItemWithIdentifier: cell_item.item)
collextionView.delegate = self
collextionView.dataSource = self
collextionView.isSelectable = true
// Do any additional setup after loading the view.
}
override var representedobject: Any? {
didSet {
// Update the view,if already loaded.
}
}
}
extension ViewController:NSCollectionViewDelegate,NSCollectionViewDataSource{
func collectionView(_ collectionView: NSCollectionView,numberOfItemsInSection section: Int) -> Int {
return 8
}
func collectionView(_ collectionView: NSCollectionView,itemForRepresentedobjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let item = collectionView.makeItem(withIdentifier: cell_item.item,for: indexPath)
return item
}
func collectionView(_ collectionView: NSCollectionView,didSelectItemsAt indexPaths: Set<IndexPath>) {
//No effect here
print("item select !")
}
}
class cell_item: NSCollectionViewItem {
static let item = NSUserInterfaceItemIdentifier(rawValue: "cell_item")
override func loadView() {
self.view = NSView()
self.view.wantsLayer = true
self.view.layer?.backgroundColor = #colorLiteral(red: 0.2745098174,green: 0.4862745106,blue: 0.1411764771,alpha: 1)
}
override func mouseDown(with event: NSEvent) {
print("item mouse down")
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。