如何将值从一个视图控制器传递到另一个视图控制器?

时间:2014-12-30 10:12:11

标签: ios swift

我正在使用故事板构建一个iOS应用程序。我已经使用swift在我的应用程序中实现了谷歌地图。我在标签中获取地址值。我面临一个问题,将该标签值传递给另一个类(第一个)用目标c写的视图控制器。

现在正在第一个视图控制器的故事板中发生了什么我有一个按钮,然后点击该模态segue执行打开的第二个视图控制器包含地图,这个地图视图控制器包含完成按钮,以关闭视图控制器并获取bact到第一视图控制器。

这是故事板图片:

enter image description here

这是我的代码:

在swift中映射视图控制器代码:

func reverseGeocodeCoordinate(coordinate: CLLocationCoordinate2D) {
    let geocoder = GMSGeocoder()
    geocoder.reverseGeocodeCoordinate(coordinate) { response , error in

      //Add this line
      self.addressLabel.unlock()
      if var address = response?.firstResult() {
        println("label657656558568===\(address)");

        //  self.addressLabel.text=address.valueForKey ("GMSAddress") as? NSString;
        self.addressLabel.text=address.valueForKey ("subLocality") as? NSString;

        println("label===\(self.addressLabel.text)");
        let labelHeight = self.addressLabel.intrinsicContentSize().height
        self.mapView.padding = UIEdgeInsets(top: self.topLayoutGuide.length, left: 0, bottom: labelHeight, right: 0)
        UIView.animateWithDuration(0.25) {
             self.pinImageVerticalConstraint.constant = ((labelHeight - self.topLayoutGuide.length) * 0.5)
          self.view.layoutIfNeeded()
        }
      }
    }
  }
@IBAction func doTap(x:UIButton) {

     self.dismissViewControllerAnimated(true, completion: {});//This is intended to dismiss the Info sceen.
        println("pressed")

    }

1 个答案:

答案 0 :(得分:2)

您可以在此处使用delegate protocols将值从MapViewController传递给FirstViewController。以下是示例link

相关问题