简体   繁体   English

将数据从一个视图控制器传递到同一视图上的另一个视图控制器

[英]Pass data to from one viewcontroller to another viewcontroller on the same view

I'm building my first app and I have two view controllers being displayed at the same time .我正在构建我的第一个应用程序,并且同时显示了两个视图控制器 The first is my google maps and top on of that view is a panel(pod) I found .第一个是我的谷歌地图,该视图的顶部是我找到的面板(吊舱)。 The Googlemaps viewcontroller calls up the panel which is in a separate story board. Googlemaps 视图控制器调用位于单独故事板中的面板

I'd like to be able to pass data to the panel view without having to use a segue.我希望能够将数据传递到面板视图而无需使用 segue。 I have tried the segue approach but it totally replaces the whole view.我尝试过 segue 方法,但它完全取代了整个视图。 Is there a way for me to pass Data to the panel without having to switch to that view alone?有没有办法让我将数据传递到面板而不必单独切换到该视图?

extension MapViewController: GMSMapViewDelegate {
     func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {

        guard let placeMarker = marker as? PlaceMarker else {return false}


        guard let panview = self.storyboard?.instantiateViewController(withIdentifier: "atminfo") as? PanelMaterial
        else {
            return false
        }


        panview.Titlee = placeMarker.place.name
        atmaddress = panview.Titlee ?? "Me"
        print(atmaddress)

        return false



  }

}

Above is my code, this is one the GoogleMaps ViewController, this is where I receive the info from the pin and try pass it to the Panel that is active in the same view.以上是我的代码,这是 GoogleMaps ViewController 之一,这是我从 pin 接收信息并尝试将其传递给在同一视图中处于活动状态的面板的地方。 I'm able to receive the data when I put breakpoints, but passing the data whilst the panel is still active in my GoogleMaps View doesn't display.当我放置断点时,我能够接收数据,但是当面板在我的 GoogleMaps 视图中仍然处于活动状态时传递数据不会显示。

Any help is appreciated.任何帮助表示赞赏。

you can also use singleton classes to passing the data to different controller or you can create object in appdelegate it can also used from any class. you can also use singleton classes to passing the data to different controller or you can create object in appdelegate it can also used from any class.

like this:像这样:

Declare variable in appdelegate在 appdelegate 中声明变量

var channelID = ""

you can use like你可以使用喜欢

let kAppDelegate = UIApplication.shared.delegate as! AppDelegate
print(kAppDelegate.channelID)

暂无
暂无

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

相关问题 将数据从一个标签栏视图控制器传递到另一标签栏视图控制器 - pass data from one tabbar viewcontroller to another tabbar viewcontroller Swift 3将数据从一个ViewController传递到另一个ViewController - Swift 3 pass data from one ViewController to another ViewController 将UISwitch状态从一个View Controller传递到另一个ViewController - Pass UISwitch State from One View Controller to Another ViewController 如何将NSMutableDictionary从一个viewController传递到另一个View控制器? - How to pass NSMutableDictionary from one viewController to another View controller? 将nsmutablearray从一个ViewController传递到另一个View Controller - Pass nsmutablearray from one viewcontroller to another view controller 将一个变量从一个viewcontroller传递给另一个viewcontroller - Pass one variable from one viewcontroller to another viewcontroller 从Cloudkit获取的数据从一个ViewController传递到另一个ViewController - Pass data fetched from Cloudkit from one viewcontroller to another 如何快速将图像从一个视图控制器传递到另一个视图控制器? - How to pass an image from one viewcontroller to another viewcontroller in swift? 从一个ViewController传递一个整数值到另一个ViewController并在UITextField中显示它 - Pass an integer value from one ViewController to another ViewController and display it in UITextField 将Json响应从一个Viewcontroller传递到另一个Viewcontroller并填充CollectionView - Pass Json response from one Viewcontroller to another Viewcontroller and populate CollectionView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM