У меня есть три ViewController с UILabel (SpeedDisplay), и я хочу иметь возможность установить тип информации (MPH / KMH) из сегментированного контроллера, расположенного в его собственном viewController. Заранее благодарю за любую помощь.
Вот мой код:
«Первый ViewController»:
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, CALayerDelegate {
@IBOutlet weak var speedDisplay: UILabel!
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
.....
let speed = location.speed
if speed < 1 {
self.speedDisplay?.text = "0.0"
}
else {
self.speedDisplay?.text = String(format: "%.1f", speed * 3.6, "km/h")
}
print(speed, "speed")
"SecondViewController":
class MapViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, CALayerDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var speedDisplay: UILabel!
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
.....
let speed = location.speed
if speed < 1 {
self.speedDisplay?.text = "0.0"
}
else {
self.speedDisplay?.text = String(format: "%.1f", speed * 3.6, "km/h")
}
print(speed, "speed")
"ThirdViewController":
class HudViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, UIGestureRecognizerDelegate, UIApplicationDelegate {
@IBOutlet weak var speedDisplay: UILabel!
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
.....
let speed = location.speed
if speed < 1 {
self.speedDisplay?.text = "0.0"
}
else {
self.speedDisplay?.text = String(format: "%.1f", speed * 3.6, "km/h")
}
print(speed, "speed")
"PopUpViewController":
class PopupViewController: UIViewController {
@IBOutlet weak var speedSC: UIView!
@IBOutlet weak var tempSC: UIView!
@IBOutlet weak var altitudeSC: UIView!
@IBOutlet weak var doneButton: UIView!
@IBAction func speedSC(_ sender: UISegmentedControl) {
let speedIndex = sender.selectedSegmentIndex
switch speedIndex {