且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试制作3列可删除按钮的行,但此处不起作用

更新时间:2023-12-04 12:01:28

您可以在 ForEach 的末尾添加一个显式的 .id -因为您正在使用一个静态的 ForEach ,您可能需要强制刷新它.

You can add an explicit .id at the end of the ForEach - since you're using a static ForEach you may need to force refresh it.

在上一篇文章中,您使用了动态的 ForEach (带有 id 参数).这就是它起作用的原因.

In your previous post you used a dynamic ForEach (with the id parameter). That's why it worked.

ForEach(0 ..< someData.buttonObjects.count / 3 + 1) { row in // create number of rows
    HStack {
        ForEach(0 ..< 3) { column in // create 3 columns
            self.makeView(row: row, column: column)

        }
    }
}
.id(UUID()) // <- add this line