简体   繁体   English

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

[英]How to pass value from one view controller to another swift?

I'm building an iOS app using storyboards.I have implemented google maps in my app using swift.I'm getting address value in a label.I'm facing an issue to pass that label value to another class(First view controller) written in objective c. 我正在使用情节提要构建iOS应用程序。我已经在我的应用程序中使用swift实现了谷歌地图。我正在获取标签中的地址值。我面临着将该标签值传递给另一个类的问题(第一个视图控制器)用目标写成c。

What is happening right now in storyboards in first view controller i have a button and on click on that modal segue perform open second view controller contain map and this map view controller contain done button to dismiss the view controller and get bact to the first view controller. 现在,在第一个视图控制器中的情节提要中发生了什么,我有一个按钮,然后单击该模式按钮即可执行以打开第二个视图控制器包含地图,并且此地图视图控制器包含“完成”按钮以关闭视图控制器并将bact传递给第一个视图控制器。

Here is storyboard image: 这是情节提要图像:

在此处输入图片说明

here is my code: 这是我的代码:

Map View Controller code in swift: 快速的Map View Controller代码:

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

    }

you can use delegate protocols here to pass the value from MapViewController to FirstViewController. 您可以在此处使用委托协议将值从MapViewController传递给FirstViewController。 Here is the example link 这是示例链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将UI ImageView从一个视图控制器传递到另一个? 迅捷3 - how to pass a UI ImageView from one view controller to another? swift 3 无法将值从一个View Controller传递到另一个View Controller - Not able to pass value from one View Controller to another View Controller 使用Firebase将图像从一个视图控制器传递到另一个(swift) - pass an image from one view controller to another (swift) with Firebase 如何将字典从一个视图 controller class 传递到另一个视图?SWIFT - How can I pass dictionary from one view controller class to another?SWIFT 如何在 Swift 中以编程方式从一个控制器导航到另一个视图控制器? - How to navigate from one controller to another View Controller programmatically in Swift? 无法将值从一个视图控制器传递到情节提要上的另一个 - Not able to pass value from one view controller to another on storyboard 如何在不使用segue的情况下将一些值从一个视图控制器传递给Swift 4中的UINavigationController? - How do I pass some value from one view controller to UINavigationController in swift 4 without using segue? 将json ID从一个表视图控制器传递到Swift 3中的另一个表视图控制器 - pass json id from one table view controller into another table view controller in swift 3 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 如何将数据从一个视图控制器传递到另一个SWIFT - How to pass data from one view controller to the other SWIFT
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM