self.presentationMode.wrappedValue.sdisse()在SwiftUI中不起作用



这是登录页面的代码,使用导航链接从tabview导航,在这里我想在得到api响应后弹出

此外,如果有任何方法可以使用navigationLink弹出相同的链接推送,请告诉我。

提前感谢

struct LoginBody: View {
@ObservedObject var viewModel = LoginViewModel()
@State private var email: String = ""
@State private var password: String = ""

@Environment(.presentationMode) private var presentationMode: Binding<PresentationMode>

var loginButton: some View { 
Button(action: {
DispatchQueue.main.async {
print("Email:- ", email)
print("Password:- ", password)

viewModel.loginAPI(email: email, password: password)

DispatchQueue.main.asyncAfter(deadline: .now() + 8, execute: {
print("presentationMode dismiss")
self.presentationMode.wrappedValue.dismiss()
})
}
}) {
HStack(alignment: .center) {
Spacer()
Text("Login")
.font(.system(size: 20).bold())
.frame(alignment: .center)
Spacer()
}
}
.padding(EdgeInsets(top: 15, leading: 20, bottom: 15, trailing: 20))
.background(Color(#colorLiteral(red: 0.3340760444, green: 0.764342023, blue: 0.8197288968, alpha: 1)))
.foregroundColor(Color.white)
.cornerRadius(5)
.shadow(color: Color.init(red: 0.0, green: 0.0, blue: 0.0, opacity: 0.4), radius: 2, x: 0, y: 2)
.frame(height: 40, alignment: .center)
}

}

不知道如何编译,但重命名"登录按钮";至";身体";。

最新更新