简体   繁体   English

点击按钮时转到新视图(SwiftUI)

[英]Go to a new view when button tapped (SwiftUI)

My expectation: I want to open a new full screen view (PhoneNumberView) on click of confirmation dialog button.我的期望:我想在单击确认对话框按钮时打开一个新的全屏视图 (PhoneNumberView)。 Reality: Nothing happens when I click to Back button (please check my code below)现实:当我点击“后退”按钮时没有任何反应(请检查下面的代码)

Here is my code:这是我的代码:

                SetPasswordButton(value: "exitButton",
                                  password: $password,
                                  key: $key,
                                  unlocked: $unlocked,
                                  repeatPassword: $repeatPassword, isExitButtonTapped: $isExitButtonTapped)
                .confirmationDialog("", isPresented: $isExitButtonTapped) {
                    
                    Button("Back", role: .destructive) {
                        goToPhoneScreen = true
                    }
                    .fullScreenCover(isPresented: $goToPhoneScreen {
                            PhoneNumberView()
                    }                   
                    
                    Button("Cancel", role: .cancel) {}
                }

Could you help me?你可以帮帮我吗?

You have misplaced the .fullScreenCover in your code, that should be something like this, i have tested it and it's working as expected, here is the Full code,您在代码中放错了.fullScreenCover ,应该是这样的,我已经对其进行了测试并且它按预期工作,这是完整代码,

struct ContentView: View {

var body: some View {
    SetPasswordButton(value: "exitButton",
                      password: $password,
                      key: $key,
                      unlocked: $unlocked,
                      repeatPassword: $repeatPassword, isExitButtonTapped: $isExitButtonTapped)
    .confirmationDialog("", isPresented: $isExitButtonTapped) {
        Button("Back") {
            goToPhoneScreen = true
        }
    }
    .fullScreenCover(isPresented: $goToPhoneScreen){
        PhoneNumberView()
    }
    Button("Cancel", role: .cancel) {}
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM