SwiftUI - 代码中的 ForEach 循环未显示在选项卡上

问题描述

在我的 1 = MYFUN(param1) // Param1 can be an identifier string number or MYFUN2 or MYFUN3 2 = MYFUN2(param1,param2) // Param1,param2 can be an identifier string number or MYFUN1 or MYFUN2 or MYFUN3 2 = MYFUN3(param1,param2,param3) // // Param1,param3 can be an identifier string number or MYFUN1 or MYFUN2 or MYFUN3 中,我的循环没有显示在预览中。我错过了什么吗?仍在快速学习...

.tabItem 3

解决方法

您的 ForEach 位于 .tabItem 内,它是标签栏图标。小按钮不可能显示 100 个项目。

我假设您希望 ForEach 成为该标签的屏幕?

Tab 3 active,showing 100 rows of 'This is tab 3!'

只需将 VStack 放在 .tabItem 之前。

VStack {
    List{
        ForEach(0..<100) { index in
            Text("This is tab 3!")
        }
    }
}
.tabItem {
    VStack {
        Image(systemName: "gamecontroller")
        Text("Tab 3")
        
    }
}