如何在SwiftUI中为一个导航链接设置多个目的地



我想为一个基于布尔值的导航链接获取多个目的地。我怎样才能做到这一点?

HStack {
Spacer()
NavigationLink(
destination: isSignUpView == true ? SetupPassView() : ForgetView(),
isActive: $showSetupPassView,
label: {
Button(action: {enterEmailApi()}, label: {
NextButtonView(isAnimating: $showLoading)
})
})
}

我得到这个错误:

Result values in '? :' expression have mismatching types 'SetupPassView' and 'ForgetView'

以下是可能的解决方案(请注意(:

NavigationLink(
destination: isSignUpView ? AnyView(SetupPassView()) : AnyView(ForgetView()),
isActive: $showSetupPassView,
...
HStack {
if isSignUwView {
NavigationLink(
destination: SetupPassView(),
isActive: $showSetupPassView,
label: {
Button(action: {enterEmailApi()}, label: {
NextButtonView(isAnimating: $showLoading)
})
})
} else {
NavigationLink(
destination: ForgetView(),
isActive: $showSetupPassView,
label: {
Button(action: {enterEmailApi()}, label: {
NextButtonView(isAnimating: $showLoading)
})
})
}

相关内容

  • 没有找到相关文章

最新更新