xcode SwiftUI弹出窗口不会关闭

ar5n3qh5  于 2023-01-14  发布在  Swift
关注(0)|答案(1)|浏览(123)

我正在实现一个弹出窗口来显示一个实验的结果,除了弹出窗口外一切正常。问题是,如果我按下按钮关闭弹出窗口,它就不工作了。

我曾经寻找过一些解决方案,但是没有一个能成功。我试过使用wrapped.dismiss(),Binding,但是没有一个能成功。
以下是弹出窗口的代码:

struct popUpExito: View{
    
    @Environment(\.presentationMode) var presentation
    @EnvironmentObject var vm: ViewModel
    @ObservedObject var datos = DatosExp()
    
    @Binding var visible: Bool
    
    var body: some View{
        Color(red: 90 / 255, green: 163 / 255, blue: 100 / 255)
            .ignoresSafeArea()
            .overlay(
                VStack{
                    Spacer()
                    Text("Guardado con éxito")
                        .font(.title)
                    Spacer()
                    Text("El cristal es de tipo:")
                        .font(.title3)
                    
                    Text("\(tipoNombre)")
                        .font(.title2)
                    
                   
                    Button("Aceptar"){
                        //presentation.wrappedValue.dismiss()
                        visible = false
                    }
                    .frame(width: 150, height: 55)
                    .background(.green)
                    .foregroundColor(.white)
                    .clipShape(RoundedRectangle(cornerRadius: 30))
                    Spacer()
                }
                
            )    }
}

这是启动弹出窗口的视图:

struct RevisionDatosExp: View{
    @Environment(\.presentationMode) var presentation
    @EnvironmentObject var vm: ViewModel
    @ObservedObject var datos = DatosExp()
    
    @State var popUpVisible = false
    
    
    var body: some View{
        Color(red: 48 / 255, green: 49 / 255, blue: 54 / 255)
            .ignoresSafeArea()
            .overlay(
                VStack{
                    Text("Revision de los datos")
                        .font(.title)
                        //.padding(.bottom, 10)
                    Spacer()
                //SOME OF THE DATA .....

                    HStack{
                        Button("Volver atrás"){
                            presentation.wrappedValue.dismiss()
                        }
                        .frame(width: 150, height: 55)
                        .background(rojoboton)
                        .foregroundColor(.white)
                        .clipShape(RoundedRectangle(cornerRadius: 30))
                        
                       
                        Text("Confirmar").onTapGesture {
                                self.popUpVisible = true
                            
                           //op1
                           //op2
                            }
                                .frame(width: 150, height: 55)
                                .background(colorboton)
                                .foregroundColor(.white)
                                .clipShape(RoundedRectangle(cornerRadius: 30))

                            //Aqui navegamos al popup
                                
                        NavigationLink(destination:AnadirDatosExpView(), isActive: $popUpVisible){
                            EmptyView()
                        }.sheet(isPresented: $popUpVisible){
                            popUpExito( visible: self.$popUpVisible)
                        }
                    }
                    Spacer()
                }.frame(width: 295)
                    .foregroundColor(Color(red: 255 / 255, green: 255 / 255, blue: 255 / 255))
                    .navigationBarBackButtonHidden(true)
                
            )
    }
}

``
qyyhg6bp

qyyhg6bp1#

我认为那张表和navigationLink在同一层。我把那张表放在navigationBarBackButtonHidden上面,它对我来说很好用:-)
问候你,艾伯特

相关问题