0

我必须像实现一样在屏幕中创建一个登录屏幕,用户可以输入手机号码并单击登录按钮模型表将在 OTP 验证表必须关闭并在仪表板上导航后打开以进行顶部验证。

在这里,我在该 contentView 上创建了一个内容视图,单击打开模型按钮,模型表(sheetView)将在单击完成按钮表后打开,然后屏幕从ContentView导航到DashboardView

// 内容视图

struct ContentView: View {

    @State var isAction: Bool = false
    @State var isDashboard: Bool = false

    var body: some View {

        NavigationView{

            Button(action: {
                self.isAction.toggle()
            }) {
                Text("Open Model")
            }.sheet(isPresented: $isAction) {

                sheetView(isDissmis: self.$isAction) { (isNavigateOnDashboard) in

                    print(isNavigateOnDashboard ?? false)

                    return self.isDashboard = isNavigateOnDashboard ?? false
                }
            }
            NavigationLink(destination: DashboardView(), isActive: self.$isDashboard) {
                EmptyView()
            }
        }
    }
}

//sheetView:-modalPresentationStyle以工作表的形式呈现。

struct sheetView: View {

    @Binding var isDissmis: Bool
    var isNavigateDashboard: ((Bool?)) -> Void?
    var body: some View {

        NavigationView{
            Text("Here i have to verifiy Some details")
                .navigationBarItems(trailing: doneButton)
        }
    }

    var doneButton: some  View {

        Button(action: {
            self.isDissmis = false
            self.isNavigateDashboard(true)
        }) {
            Text("Done").bold()
        }
    }
}

//仪表板:-关闭模型(工作表)屏幕后应在仪表板上导航。

struct DashboardView: View {

    var body: some View {

        TabView{

            Text("Home").tabItem{
                Image(systemName: "1.circle")
                Text("Home")
            }

            Text("Activity").tabItem{
                Image(systemName: "2.circle")
                Text("Activity")
            }
            Text("profile").tabItem{
                Image(systemName: "3.circle")
                Text("profile")
            }
        }
    }
}

有什么线索吗?

4

1 回答 1

1

您可以ContentView body通过这种方式更改您的,当您关闭工作表视图时,它将导航到DashboardView

此外,无需在您的SheetView


var body: some View {
        NavigationView{
            VStack {
                Button(action: {
                    self.isAction.toggle()
                }) {
                    Text("Open Model")
                }.sheet(isPresented: $isAction, onDismiss: {
                    self.isDashboard.toggle()
                }) {
                    sheetView(isDissmis: self.$isAction)
                }
                NavigationLink(destination: DashboardView(), isActive: $isDashboard) {
                    EmptyView()
                }
            }
        }
    }
于 2020-02-28T21:06:59.533 回答