从警报打开视图

时间:2020-06-12 21:30:46

标签: swift swiftui

如何在SwiftUI中从警报打开视图? 它必须具有2个按钮,一个打开视图A,另一个打开视图B。 我试图创建一个自定义视图,但是当我单击NavigationLink按钮转到另一个视图并返回时,仍会出现警报。 这是代码:

import SwiftUI

struct AlertTemperature: View {

    @Binding var activeMessage: Bool
    @State var activeYes: Bool = false
    @State var activeNo: Bool = false
    @ObservedObject var viewRouter : ViewRouter

    var body: some View {
        VStack{
            Text("¿Desea tomar la temperatura?")
                .padding(.bottom,20)
            HStack{
                NavigationLink(destination: QuickTempView(viewRouter: self.viewRouter), isActive: $activeYes){
                    Button(action: {
                        //print("Di clic en si")
                        self.activeYes.toggle()
                        self.activeMessage.toggle()
                    }){
                        HStack{
                            Spacer()
                            Text("Si")
                                .padding(.all,10)
                            Spacer()
                        }
                    }
                        .background(Color("DarkBlue"))
                        .foregroundColor(.white)
                }.padding(.bottom,20)
                    .padding(.leading,20)
                    .padding(.trailing,10)

                NavigationLink(destination: PreConfirmView(viewRouter: self.viewRouter), isActive: $activeNo){
                    Button(action: {
                        //print("Di clic en no")
                        self.activeMessage = false
                        self.activeNo.toggle()
                    }){
                        HStack{
                            Spacer()
                            Text("No")
                                .padding(.all,10)
                            Spacer()
                        }
                    }
                    .background(Color("DarkBlue"))
                        .foregroundColor(.white)
                }.padding(.bottom,20)
                .padding(.leading,10)
                .padding(.trailing,20)
            }
        }.padding(20)
        .background(Color.white)
        .cornerRadius(15)
    }
}

0 个答案:

没有答案