【发布时间】:2021-11-30 01:44:57
【问题描述】:
我想使用 ForEach 循环,但它不起作用。
let navigation = [["Kunde", "person"], ["Wartung", "gear"]]
NavigationView {
List {
NavigationLink(destination: ListView(title: "Kunde")) {
Label("Kunde", systemImage: "person")
}
NavigationLink(destination: ListView(title: "Wartung")) {
Label("Wartung", systemImage: "gear")
}
// MANY MORE
}
}
我的方法打印从 0 到 7 的数字,但我想要数组的内容。
我的做法:
let navigation = [["Kunde", "person"], ["Wartung", "gear"]]
NavigationView {
List {
ForEach(navigation.indices) { index in
NavigationLink(destination: ListView(title: "\(index)")) {
Label("\(self.index)", systemImage: "\(index)")
}
}
}
}
【问题讨论】: