Programming Learner
Programming Learner

Reputation: 4411

How can i show UIViewControllerRepresentable screen on button tap from UIViewRepresentable

I am working on a SwiftUI project, in my app i have to show a map, i am able to show map using UIViewRepresentable, now that map view will have a button and on tapping on that button mapview will needs to show controller (full screen direction) view and i know i can do this using UIViewControllerRepresentable.

I need help in which how can i show the UIViewControllerRepresentable from button click of UIViewRepresentable

Till now what i have done is, adding my code :

On button click i am calling showDetailMap function which calls the MapDetailViewController , but some how MapDetailViewController is not opening as model.

private func showDetailMap() {
    MapDetailViewController()
}

struct MapDetailViewController: UIViewControllerRepresentable {

func makeUIViewController(context: Context) -> MapDetailViewController {
    let viewController: MapDetailViewController = MapDetailViewController()
    return viewController
}

func updateUIViewController(_ uiViewController: MapDetailViewController, context: Context) {}


}

Please help me with this.

Upvotes: 0

Views: 1243

Answers (1)

Threadripper
Threadripper

Reputation: 652

    struct ContentView: View {
    
     @State var isPresentVC = false
    
     var body: some View {
     
           ZStack {
                Button("OpenMapVC") {
                    isPresentVC = true
                }
                
            }.fullScreenCover(isPresented: $isPresentVC, content: {
               MapDetailViewController()
            })
       }
  }

Upvotes: 1

Related Questions