更新时间:2023-12-04 21:11:16
我找到了答案.如果要在回调中显示其他视图,则应
I've found the answer. If you want to show another view on callback you should
1)创建状态@State var pushActive = false
2)当ViewModel通知登录成功时,将pushActive
设置为true
2) When ViewModel notifies that login is successful set pushActive
to true
func handleSuccessfullLogin() {
self.pushActive = true
print("handleSuccessfullLogin")
}
3)创建隐藏的NavigationLink
并绑定到该状态
3) Create hidden NavigationLink
and bind to that state
NavigationLink(destination: ProfileView(viewModel: ProfileViewModelImpl()), isActive: self.pushActive) {
Text("")
}.hidden()