I have an NSViewController
defined in my storyboard that contains a view that holds various labels and a button. They are aligned using auto layout.
I want to use this as a UI prototype so that I can generate lots of these and add them to a vertical NSStackView
much like table rows.
I have a subclass of my NSViewController
defined like this:
class ApproachRowVC: NSViewController {
@IBOutlet var quantityLabel: NSTextField!
@IBOutlet var detailsLabel: NSTextField!
@IBOutlet var holdingLabel: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func clickDelete(_ sender: Any) {
print("Delete")
}
}
In the controller where I have the NSStackView
and want to add these rows, I have tried something along these lines, but I'm mostly confused how this is supposed to happen. This doesn't work, but I'm unsure how to proceed:
let test = ["one", "two", "three"]
for label in test{
let approachRowVC = self.storyboard?.instantiateController(withIdentifier: "ApproachRow") as! ApproachRowVC
approachRowVC.quantityLabel.stringValue = label
approachList.addArrangedSubview(approachRowVC.view)
}
Any recommendations on how to pull this off?