如何解决NSCollectionViewItem 没有选择 swift
美好的一天,
我有一个 NSCollectionView,它是可选的并且工作正常。我创建了另一个 NSCollectionView,下面的自定义 NSCollectionViewItem 是 NSCollectionViewItem 的代码
class DocumentItem: NSCollectionViewItem {
var itemView: DocumentTextView?
override func viewDidLoad() {
super.viewDidLoad()
self.itemView?.wantsLayer = true
// Do view setup here.
}
override func loadView() {
self.itemView = DocumentTextView(frame: NSZeroRect)
self.view = self.itemView!
}
func getView() -> DocumentTextView {
return self.itemView!
}
override var isSelected: Bool {
didSet {
self.itemView?.layer?.backgroundColor = isSelected ? NSColor.darkGray.cgColor : NSColor.clear.cgColor
}
}
}
以下是 DocumentTextView 的代码
class DocumentTextView: NSTextView {
var theContainer = NSTextContainer()
var theStorage = NSTextStorage()
var theManager = NSLayoutManager()
override init(frame frameRect: NSRect) {
super.init(frame: NSRect(origin: frameRect.origin,size: NSSize(width: 765,height: 1081.84414 )),textContainer: theContainer)
theContainer.containerSize = NSSize(width: 765,height: 1081.84414)
theStorage.addLayoutManager(theManager)
theManager.addTextContainer(theContainer)
self.textContainerInset = CGSize(width: 50,height: 50)
self.textContainer?.widthTracksTextView = false
self.textContainer?.heighttracksTextView = false
self.textContainer?.lineBreakMode = .byClipping
self.maxSize = NSSize(width: 765,height: 1081.84414)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func image() -> NSImageView {
let imageRepresentation = bitmapImageRepForCachingdisplay(in: bounds)!
cachedisplay(in: bounds,to: imageRepresentation)
let theImage = NSImage(cgImage: imageRepresentation.cgImage!,size: CGSize(width: 170,height: 240))
return NSImageView(image: theImage)
}
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
}
}
我已经将 NSCollectionView 设置为可以在界面构建器中选择,但由于某种原因它不可选择。覆盖的 isSelectable 变量没有触发,我无法访问任何选择索引。非常感谢任何帮助
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。