SwiftUI ForEach based on State int

后端 未结 2 515
日久生厌
日久生厌 2020-12-22 02:13

I am storing a Int value as State in my View. When I press a button the Int increase by one. This is working fine when I print my int value.

I have now a ForEach loo

2条回答
  •  臣服心动
    2020-12-22 02:34

    It is not due to state, it is because you use ForEach constructor with constant Range, it is documented feature, so not supposed to update, so it is not updated. The simplest solution is as following - to use identifier joined to your state. It just indicates for rendering engine that ForEach is new so refresh (Tested with Xcode 11.2 / iOS 13.2)

    ForEach(0..

提交回复
热议问题