Swift UI 为什么我有 2 个后退按钮?

bai*_*ain 1 navigationview swiftui

我正在尝试解决我的应用程序视图上有 2 个“后退按钮”的问题。这似乎是在我导航两次后发生的。一次从主屏幕创建帐户页面,然后再次从创建帐户页面转到另一个页面。使用导航视图两个后退按钮

我将此格式用于不同的页面。

struct CreateAccountViewGeo: View {
var body: some View {
    NavigationView{

        GeometryReader { (deviceSize: GeometryProxy) in
            ZStack{
 NavigationLink(destination: SportPreference(), tag: 1, selection: self.$current) {
                        EmptyView()
                    }
                    VStack (spacing: deviceSize.size.height * (20/812)){
                        Button(action: {
                            self.current = 1
                            print("Create tapped!")

                        }) {
                            Text("Create")
                                .fontWeight(.bold)
                                .foregroundColor(.orange)
                                .frame(width: deviceSize.size.width*(185/375), height: deviceSize.size.height*(50/812))
                                .cornerRadius(50)
                                .overlay(
                                    Capsule(style: .continuous)
                                        .stroke(Color.orange, style: StrokeStyle(lineWidth: 2)))
                                .frame(width: deviceSize.size.width, alignment: .center)

                        }//Close button for create
}
}
}
}
Run Code Online (Sandbox Code Playgroud)

E.C*_*oms 5

你有不止一个NavigationView{...}地方

  • 您只需要主屏幕上的一个导航视图。您不能在任何子视图中添加其他导航视图 (2认同)