Как мне сделать сегментированное управление обновлением UILabel на нескольких ViewControllers - PullRequest
0 голосов
/ 06 ноября 2018

У меня есть три 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 {
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...