如何使segmentedControl更新多个ViewController上的UILabel

时间:2018-11-06 02:30:59

标签: ios iphone xcode swift4

我有三个带有UILabel(SpeedDisplay)的ViewController,并且我希望能够从位于其自己的viewController中的segmentedControl设置信息类型(MPH / KMH)。在此先感谢您的帮助。 这是我的代码:

“第一个ViewController”:

Content-Length

“ SecondViewController”:

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")

“ ThirdViewController”:

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")

“ PopUpViewController”:

 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")

0 个答案:

没有答案
相关问题