Problems with layout of some rows in SwiftUI list

前端 未结 2 1463
不知归路
不知归路 2020-12-11 07:20

I have tried to find a similar problem asked before, but failed.

I have a simple view with list. I am using a ForEach to show 10 iterations of the some list item to

2条回答
  •  一整个雨季
    2020-12-11 07:55

    I tried your code at simulators first and had same issue too. But then I remembered, that there are some problems with 13.2 iOS and tried to run it on my device (iPhone 7, iOS 13.1.1) and everything works fine! I think that is the problem in 13.2 iOS, not in the List. There is sample, how I changed code for demonstration that everything is ok:

    import SwiftUI
    
    struct LocksView: View {
        
        @State private var locksPaid = 0
    
        var body: some View {
            NavigationView {
                List {
                    Picker(selection: $locksPaid, label: Text("Picker")) {
                        Text("All").tag(0)
                        Text("Not paid (2)").tag(1)
                    }
                    .pickerStyle(SegmentedPickerStyle())
                    .padding(10)
    
                    ForEach(0 ..< 200) {item in
                        LocksItemView(number: item)
                    }
    
                }
                .navigationBarTitle(Text("Locks"))
                .navigationBarItems(trailing: EditButton())
            }
        }
    }
    
    struct LocksItemView: View {
    
        @State private var paid : Bool = false
        var number: Int
    
        var body: some View {
            HStack {
    
                Text("L\(self.number)")
                    .font(.title)
                    .fontWeight(.heavy)
                    .multilineTextAlignment(.center)
                    .frame(width: 80)
    
                VStack(alignment: .leading) {
                    Text("nickname")
                        .fontWeight(.bold)
                    Text("category")
                    Text("4 000 THB")
                        .fontWeight(.bold)
                }
    
                Spacer()
    
                Toggle(isOn: self.$paid) {
                    Text("Paid")
                }
                .labelsHidden()
            }
        }
    }
    

    and on my phone the result is:

    so there are bugs in 13.2 version and I hope Apple will fix them all

提交回复
热议问题