gpt4 book ai didi

swift - 如何在 SwiftUI TabView 中设置默认选项卡?

转载 作者:行者123 更新时间:2023-12-02 00:00:40 26 4
gpt4 key购买 nike

我在 SwiftUI 中有一个 TabView,并希望在启动应用程序时将第二个选项卡设为默认选项卡。

我还没有找到任何文档来提供这种行为,但这应该是可能的。大多数应用程序都将中间选项卡作为默认选项卡。

TabView {
QuestionView()
.tabItem {
Image(systemName: "questionmark")
Text("Questions")
}
DataView()
.tabItem {
Image(systemName: "chart.bar.fill")
Text("Data")
}
Text("Empty Tab right now")
.tabItem {
Image(systemName: "bolt.horizontal.fill")
Text("Trend")
}
}

最佳答案

@State private var selection = 3

TabView(selection:$selection) {
QuestionView()
.tabItem {
Image(systemName: "questionmark")
Text("Questions")
}
.tag(1)
DataView()
.tabItem {
Image(systemName: "chart.bar.fill")
Text("Data")
}
.tag(2)
Text("Empty Tab right now")
.tabItem {
Image(systemName: "bolt.horizontal.fill")
Text("Trend")
}
.tag(3)
}

在本例中,我设置默认选择第三个选项卡。将选择更改为所需的选项卡

关于swift - 如何在 SwiftUI TabView 中设置默认选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57802440/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com