【发布时间】:2019-11-19 11:34:29
【问题描述】:
我尝试使用 SwiftUI 做一个列表,您可以在其中插入两个字符串在文本字段中,并在每一行中插入一个布尔按钮。但是,当列表超出屏幕并且您滚动到最后一行时,它们有时会删除内容。 我创建了一个最小的例子:
struct ContentView: View {
@State var bindOne = "one"
@State var bindTwo = "two"
@State var bindThree = "three"
@State var bindFour = "four"
@State var bindFive = "five"
@State var bindSix = "six"
@State var buttonValue = false
var body: some View {
VStack{
Text("test")
.font(.largeTitle)
List{
Row(someBind: bindOne, buttonValue: false)
Row(someBind: bindTwo, buttonValue: false)
Row(someBind: bindThree, buttonValue: false)
Row(someBind: bindFour, buttonValue: false)
Row(someBind: bindFive, buttonValue: false)
Row(someBind: bindSix, buttonValue: false)
}
}
}
}
与支持视图:
struct Row: View {
@State var someBind: String
@State var buttonValue: Bool
var body: some View {
HStack{
TextField(someBind, text: $someBind)
.font(.largeTitle)
TextField(someBind, text: $someBind)
.font(.largeTitle)
Button(action: {self.buttonValue.toggle()}){
if buttonValue{
Text("Yes")
.font(.largeTitle)
}else{
Text("No")
.font(.largeTitle)
}
}
}
.padding(.vertical, 70)
}
}
结果是
当线条适合屏幕时没有问题,但有时你只是有一个很长的列表。 这是一个错误还是我错过了什么?
【问题讨论】:
-
您使用哪个 Xcode 版本?您可能会遇到与here 所述相同的问题
-
我使用的是 11.2.1 (11B500)。是的,可以连接。
-
它在 11.1 上为我工作
-
在 13.2 上确认问题,在 13.0 上工作
-
在 11.2+ 中,
List滚动后的行布局似乎存在很多问题。参见this answer 和file feedback