SwiftUI - List - UIViewRepresantable won't be updated

前端 未结 1 1297
耶瑟儿~
耶瑟儿~ 2021-01-15 05:53

In my list, my UIViewRepresentable won\'t be updated if it is the only item in list. If I add e.g. a Text to it, it works. To see the effect, scroll down and up again. What

相关标签:
1条回答
  • 2021-01-15 06:25

    For now I know variant/workaround that works (tested on all available Xcode 11.x)

    var body: some View {
        VStack {
            List(data.names, id: \.self) { name in
                Test(text: name).id(name) //           << here !!
            }
        }
    }
    

    Note: it might be performance drop on very big lists, but in most usual cases it is not remarkable.

    PS: By the way, about class Data - don't name your classes with same names as system one, there might be confuses and unexpectable issues.

    0 讨论(0)
提交回复
热议问题