UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SwiftUI PencilKit Navigation and UIViewControllerRepresentables

Forums > SwiftUI

Rather than selecting from a list, I'm trying to navigate between drawings like a book using buttons to cycle through, but the canvas doesn't update.

I'm following the great tutorial by DevTechie at https://www.youtube.com/watch?v=amZH2i6l004&list=PLbrKvTeCrFAfoACvHOPWFmDIaKUqBZgEr&index=5

The github is here https://github.com/devtechie/DrawingDocuments

Here's my ContentView. I thought changing the id parameter would change the drawing displayed on the canvas. But it seems like DrawingWrapper isn't updating.

DrawingWrapper(UIViewControllerRepresentable) uses a DrawingManager to pull from CoreData and DrawingViewController to define a PKCanvas.

struct ContentView: View {
  @StateObject var manager = DrawingManager()
  @State var addNewShown = false
  @State var pageNumber: Int = 0
  @State var newVar = UUID()

  var body: some View {
    VStack{
      Text(manager.docs[pageNumber].name!)
      HStack{
        Button(action:{
          pageNumber -= 1
          newVar = manager.docs[pageNumber].id!
        }){
          Image(systemName: "chevron.left")
        }
        Spacer()
        Button(action:{
          pageNumber += 1
          newVar = manager.docs[pageNumber].id!
        }){
          Image(systemName: "chevron.right")
        }
      }

      DrawingWrapper(manager: manager, id: $newVar)

    }
  }
 }

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.