【发布时间】:2020-06-23 22:10:36
【问题描述】:
我的ContentView 中有这个:
List {
ForEach(items) { Item in
ItemView(cellColor: self.$cellColor, title: item.title, orderId: "\(item.orderId)")
}
}
我想在循环的每次迭代中更新一个变量,比如说给它加 1,但我不能让 SwiftUI 来做这件事。像这样的:
var a: Int = 1
List {
ForEach(toDoItems) { toDoItem in
ToDoItemView(cellColor: self.$cellColor, title: toDoItem.title, orderId: "\(toDoItem.orderId)")
a = a + 1
}
}
但这不起作用。抱歉,如果我没有以正确的格式提出这个问题,这是我在这里的第一个问题!
【问题讨论】:
-
你是什么意思循环的每次迭代?
ForEach是一名建设者。你能解释一下吗?
标签: swiftui