Using multiple hosting controllers in SwiftUI on WatchOS

回眸只為那壹抹淺笑 提交于 2019-12-11 05:25:33

问题


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.

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 ?

来源:https://stackoverflow.com/questions/58509975/using-multiple-hosting-controllers-in-swiftui-on-watchos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!