我有一个NSSlider
. FirstViewController
我有 12NSImageViews
英寸SecondViewController
。我想在第一个窗口中移动一个滑块,并在第二个窗口中的这 12 个视图中随机播放图像。
NSImageViews
每次移动滑块时如何更新这些?
第二视图控制器
var imagesQty = 100
override func viewWillAppear() {
super.viewWillAppear()
//let arrayOfViews: [NSImageView] = [view01,...view12]
for view in arrayOfViews {
let i = Int(arc4random_uniform(UInt32(imagesQty-1)))
let image = NSImage(data: try Data(contentsOf: photos[i]))
view.image = image
}
}
视图控制器
@IBOutlet weak var slider: NSSlider!
@IBAction func segueData(_ sender: NSSlider) {
self.performSegue(withIdentifier: .secondVC, sender: slider)
}
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
if segue.identifier! == .secondVC {
if let secondViewController =
segue.destinationController as? SecondViewController {
secondViewController?.imagesQty = slider.integerValue
}
}
}