简体   繁体   中英

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.

I'd like to be able to pass data to the panel view without having to use a segue. I have tried the segue approach but it totally replaces the whole view. 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. 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.

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.

like this:

Declare variable in appdelegate

var channelID = ""

you can use like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM