【发布时间】:2021-11-25 07:54:20
【问题描述】:
你好,我有一个项目只需要在 30 多个项目的循环中显示前 5 个项目,下面是我的代码
struct Introductions: Codable, Identifiable {
let id: String
let topIntros: String?
let image: String
let date: String
}
ForEach(introductions) { introduction in
NavigationLink(destination: IntroductionDetailView(introduction: introduction)) {
IntroductionsView(introduction: introduction)
}
}
我尝试使用此方法,但 xcode 在我滚动超过第五项后崩溃了
ForEach(introductions, id: \.topIntros) { introduction in
NavigationLink(destination: IntroductionDetailView(introduction: introduction)) {
IntroductionsView(introduction: introduction)
}
}
谢谢
【问题讨论】:
-
这不是我们在这里展示代码的方式。
-
我知道我正在寻找格式化程序,但以正确的方式呈现代码还没有运气
-
终于搞定了 Ctrl K
-
var body: some View { List { ForEach(introductions.startIndex..
-
感谢您的回复,但在这种情况下我更喜欢使用 LazyVStack,我没有完全理解您的信息
标签: foreach swiftui identifiable