I have a Storyboard that contains a controller with a NSCollectionView. The Storyboard also contains a NSCollectionViewItem with outlets connected to NSCollectionViewItem subclass, FeedItem.
How do you use the the "cell" or "scene" from the Storyboard (not a separate nib file) in the itemForRepresentedObjectAt method?
This is what I have so far..
class FeedsController : NSViewController, NSCollectionViewDataSource {
@IBOutlet weak var collectionView: NSCollectionView!
override func viewDidLoad() {
super.viewDidLoad()
}
func numberOfSections(in collectionView: NSCollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
let collectionViewItem = self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "FeedItem")) as! FeedItem
collectionViewItem.urlLabel.stringValue = "http://www.seanbehan.com"
collectionViewItem.entriesLabel.stringValue = "15 Entries"
collectionViewItem.updatedLabel.stringValue = "Last Update: June 1st at 3:15PM"
return collectionViewItem
}
}
class FeedItem : NSCollectionViewItem {
@IBOutlet weak var urlLabel: NSTextField!
@IBOutlet weak var updatedLabel: NSTextField!
@IBOutlet weak var entriesLabel: NSTextField!
}
It is a MacOS Cocoa app using Swift 4.1