简体   繁体   中英

Long List with Textfields in SwiftUI

I try to do a List with SwiftUI where you can insert two Strings in Textfields and one Boolean Button in each Row. However when the list exceeds the screen and you scroll to the last rows they sometimes erase the content. I created a minimal example:

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)

            }
        }
        }
    }

with the supporting View:

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)

    }
}

The result is

截屏

When the lines fit on the screen there is no problem, but sometimes you just have a long list. Is this a bug or am I missing something?

The problem is not present anymore. Checked with Xcode Version 11.4.1 (11E503a) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM