Using multiple hosting controllers in SwiftUI on WatchOS

775 Views Asked by At

I'm trying to use multiple WKHostingController in a SwiftUI WatchOS project.

I want to be able to go from one Controller to 3 controllers.

enter image description here

The user will press a button in the first ContentView(1) (That is paired with HostingController(1)) that will then navigate them to the middle controller in the 3-grouped set HC3 (or HostingController3, with Identifier HC3)

The Code is as follows:

struct ContentView: View {
    var body: some View {
        VStack{
            NavigationLink(destinationName: "HC3"){
                Text("Go to other wk")
            }
        } 
    }
}

Hosting Controller :

class HostingController: WKHostingController<AnyView> {
    override var body: AnyView {
        return AnyView(ContentView())
    }
}

That does take me to HC3 But I cannot navigate to HC2 or HC4 to create multiple page view where the user can scroll between HC2, HC3 and HC4. HostingController 2-4 all have similar HostingControllers and ContentViews as the ones above.

I have also made sure that HC2, HC3 and HC4 have the Relationship Next Page linearly HC2 -> HC3 -> HC4

If I check the initial controller checkbox for HC2 in the Attributes Inspector I am able to navigate between HC2, HC3 and HC4 as expected, but if I check the initial controller checkbox for HC3 I am only able to navigate between HC3 and HC4 even when the same HC2 -> HC3 -> HC4 relationships exist.

I'm having two issues, the first (1) Navigating from HC1 to HC3 where HC3 has the Relationship Next Page intact ( meaning I can scroll through HC2 HC3 HC4 the second(2) Being able to have a middle Hosting controller keep it's relationship where it is a Next Page to another HostingController.

Any ideas how I can make this work ?

0

There are 0 best solutions below