[英]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.