我有一个分段控件,可以改变一些计算。 当我在与应用程序的其余部分相同的VC中使用控件时,它可以工作,但我想创建一个“设置页面”。
如何使“settingsVC”中分段控件的选定状态影响“mainVC”?
来自“mainVC”
// Metric or imperial system segmented control
let argumentForSegment = metricImperialSegment.selectedSegmentIndex
if argumentForSegment == 0 {
statusLabel.text = "\(kmtLabel)"
topSpeedLabel.text = "\(topSpeedForLabel) kmh"
averageSpeedLabel.text = "\(averageSpeedForLabel) kmh"
altitudeLabel.text = "\(altitudeNoDecimals) m"
kmhMphLabel.text = "KMH"
}
if argumentForSegment == 1 {
statusLabel.text = "\(mphForLabel)"
来自“settingsVC”
import UIKit
let argumentForSegment = metricImperialSegment
class settingsVC: UIViewController {
@IBOutlet weak var metricImperialSegment: UISegmentedControl!
@IBAction func backButton(_ sender: Any) {
performSegue(withIdentifier: "toMainView", sender: self)
}
}