SwiftUI中出现按钮太多问题
当我有10个按钮(a-j)时,这是可以的,但当超过10个时,就会发生错误(我设计了12个按钮)。SwiftUI中出现按钮太多问题,swiftui,Swiftui,当我有10个按钮(a-j)时,这是可以的,但当超过10个时,就会发生错误(我设计了12个按钮)。 有人知道怎么做吗?ViewBuilder只能容纳10个或更少的视图。因此,如果您有10个以上的视图,请使用Group将其划分为每组中较少的视图 struct Smaple:View { @State var a = false @State var b = false ... @State var l = false @State var name =
有人知道怎么做吗?ViewBuilder只能容纳10个或更少的视图。因此,如果您有10个以上的视图,请使用
Group
将其划分为每组中较少的视图
struct Smaple:View {
@State var a = false
@State var b = false
...
@State var l = false
@State var name = ""
var body: some View {
VStack(alignment: .center){
GeometryReader{ proxy in
ScrollView(.vertical){
VStack(alignment: .center){
TextField("name", text: self.name)
VStack{
Button(action:{self.a.toggle()}){Text("a")}
Button(action:{self.b.toggle()}){Text("b")}
...
Button(action:{self.k.toggle()}){Text("l")}
}
}
}
}
}.background(Color.blue)
}
}
ViewBuilder只能容纳10个或更少的视图。因此,如果您有10个以上的视图,请使用
Group
将其划分为每组中较少的视图
struct Smaple:View {
@State var a = false
@State var b = false
...
@State var l = false
@State var name = ""
var body: some View {
VStack(alignment: .center){
GeometryReader{ proxy in
ScrollView(.vertical){
VStack(alignment: .center){
TextField("name", text: self.name)
VStack{
Button(action:{self.a.toggle()}){Text("a")}
Button(action:{self.b.toggle()}){Text("b")}
...
Button(action:{self.k.toggle()}){Text("l")}
}
}
}
}
}.background(Color.blue)
}
}
在SwiftUI中,不能添加超过10个子视图。您可以使用
组
。这也将以的形式应用:
Group{
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
} // 6
Group{
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}} // 6
在SwiftUI中,不能添加超过10个子视图。您可以使用
组
。这也将以的形式应用:
Group{
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
} // 6
Group{
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}
Button(action: {} ){ Text("")}} // 6
为什么不使用列表?我尝试创建一个更自定义的列表,而不是优先级使用列表。为什么不使用列表?我尝试创建一个更自定义的列表,而不是优先级使用列表。