【发布时间】:2021-11-19 21:25:20
【问题描述】:
我有一个结构,它可以从 CoreData 中洗牌和列出记录。 我想用按钮重新加载/刷新列表视图。 我尝试使用 Button 中的功能。 有什么办法可以做到吗?
var body: some View {
VStack {
List {
ForEach(dictionary.shuffled().prefix(upTo: 10),id: \.self) { word in
HStack {
Text("\(word.englishWord)")
.foregroundColor(Color.blue)
Text("| \(word.urhoboWord) |")
.foregroundColor(Color.green)
Image(word.imageName)
.resizable()
.frame(width:40, height: 40)
}//HStack
}//End of ForEach
}//End of List
//Button to reload and shuffle list
Button(action: {}) {
Text("Shuffle")
.padding()
.background(Color.black)
.foregroundColor(Color.white)
.cornerRadius(6)
}
.navigationBarTitle(Text("Begin Learning"),displayMode: .inline)
【问题讨论】:
标签: swiftui