你可以查看我的代码有什么问题吗?我可以成功运行应用程序但内容空白。谢谢!
import Cocoa
class MainViewController: NSViewController {
@IBOutlet weak var scrollView: NSScrollView!
@IBOutlet weak var collectionView: NSCollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
self.initView()
self.initCollectionView()
}
func initView() {
let nib = NSNib(nibNamed: NSNib.Name(rawValue: "NavCollectionViewCell"), bundle: nil)
//ßßself.collectionView.register(nib, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "NavCollectionViewCell"))
self.collectionView.register(nib, forItemWithIdentifier: .collectionViewItem)
}
func initCollectionView() {
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
}
extension MainViewController: NSCollectionViewDelegate, NSCollectionViewDataSource {
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func numberOfSections(in collectionView: NSCollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
// 4
let item = collectionView.makeItem(withIdentifier: .collectionViewItem, for: indexPath)
return item
}
}
extension NSUserInterfaceItemIdentifier {
static let collectionViewItem = NSUserInterfaceItemIdentifier("NavCollectionViewCell")
}