我对 很陌生SwiftUI
,所以请耐心等待,以防我混淆了术语。
我有一个Int
@State
在 a 中使用的属性TabView
来保存当前索引。然后我有一个函数需要 aBinding<Bool>
来显示另一个视图。
我基本上想做的是每当我的Int
状态达到给定值时将一个条件传递到函数中。
示例代码:
import SwiftUI
struct FooTabView: View {
@State private var selected = 0
@State private var shouldShow: Bool = false
var body: some View {
TabView(selection: $selected) {
Text("Hello")
.tabItem {
Text("Foo")
}.tag(0)
Text("World")
.tabItem {
Text("Bar")
}.tag(1)
}.anotherFunctionReturningAView(show: shouldShow)
}
}
Run Code Online (Sandbox Code Playgroud)
可以说,只有当等于 时才shouldShow
为真。我该怎么做呢?selected
1