1

Im trying to put a navigationDestination(isPresented:destination:) for a button on Xcode14/iOS16, it executes the func and so when I press the button but it doesn't send me to the new view and also i cant see if it is passing the information from one view to another.


   Button(action: {watchGame(name: "Cuphead")} , label: {
                            
      Image("abzu")
     .resizable()
     .scaledToFit()
     .frame(width: 240, height: 135)
                            
   }).navigationDestination(isPresented: $isGameViewActive) 
      {gameView(url: url, 
        titulo: titulo, 
        studio: studio, 
        calificacion: calificacion, 
        anoPublicacion: anoPublicacion, 
        descripcion: descripcion, 
        tags: tags, 
        imgsUrl: imgsUrl)
}
                    


 func watchGame(name:String) {
        juegoEncontrado.search(gameName: name)
        DispatchQueue.main.asyncAfter(deadline: .now() + 1){
            
            print("Cantidad E: \(juegoEncontrado.gameInfo.count)")
            print("juego \(juegoEncontrado.gameInfo[0].title)")
            print(isGameViewActive)
            if juegoEncontrado.gameInfo.count == 0 {
                isGameInfoEmpty = true
            }else{
                
                url = juegoEncontrado.gameInfo[0].videosUrls.mobile
            titulo = juegoEncontrado.gameInfo[0].title
            studio = juegoEncontrado.gameInfo[0].studio
            calificacion = juegoEncontrado.gameInfo[0].contentRaiting
            anoPublicacion = juegoEncontrado.gameInfo[0].publicationYear
            descripcion = juegoEncontrado.gameInfo[0].description
            tags = juegoEncontrado.gameInfo[0].tags
            imgsUrl = juegoEncontrado.gameInfo[0].galleryImages
            isGameViewActive = true
                
              
            }
            
        }
        
    }

watchGame is my function to search the name given and return all the information strings that I need to give back to my new view, the isGameViewActive toggle is inside this function so don't worry about that, any idea on how can I solve this?

I tried putting the button or the hole view inside a NavigationStack but when I do that all the content disappears from the screen, Im not understanding this new navigation schemes. The function inside the button executes but it doesn't send me to the other view on the .navigationDestination

alandavid11
  • 11
  • 1
  • 2
  • is `isGameViewActive` inside your `watchGame(...)` function (that you don't want to show) toggled on the main thread? – workingdog support Ukraine Nov 11 '22 at 06:15
  • Let me put the function in the question but yes it is inside it – alandavid11 Nov 11 '22 at 06:23
  • maybe in `watchGame`, process is going through the `if juegoEncontrado.gameInfo.count == 0 {...}` not the `else{..}` – workingdog support Ukraine Nov 11 '22 at 06:42
  • No sir, it is executing the else statement because I put a print inside it that gives me the bool state and it is true, maybe is because it isn’t a navigationStack? But the thing is that when I put a navigation stack it disappears – alandavid11 Nov 11 '22 at 14:38
  • It is best to show a minimal reproducible code, see: https://stackoverflow.com/help/minimal-reproducible-example . Also, have a look at this link, https://developer.apple.com/documentation/swiftui/navigationstack/ it tells you that you need a `NavigationStack` to navigate. – workingdog support Ukraine Nov 11 '22 at 23:34

0 Answers0