【问题标题】:Long List with Textfields in SwiftUISwiftUI 中带有文本字段的长列表
【发布时间】: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 answerfile feedback

标签: ios swift swiftui


【解决方案1】:

问题不再存在。使用 Xcode Version 11.4.1 (11E503a) 检查。

【讨论】:

    猜你喜欢
    • 2020-06-01
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多