【问题标题】:How to insert dynamic list items into SwiftUI list?如何将动态列表项插入 SwiftUI 列表?
【发布时间】:2023-02-10 22:27:41
【问题描述】:

这是我的身体:

var body: some View {
    NavigationView {
        List {
            MonthElementView(month: month)
            ServiceElementView(service: month.services.first!)
            ServiceElementView(service: month.services.first!)
        }
    }
}

它有效。

但是我需要在这里显示每个月的服务ServiceElementView,我不知道如何使用 SwiftUI 来实现。以下解决方案不起作用:

【问题讨论】:

    标签: swiftui watchos


    【解决方案1】:

    你用错了forEach

    它是…

    ForEach(month.sortedServices) { service in
    
    }
    

    【讨论】:

    • 为什么它会有所不同......但是好的,它工作得很好;)谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多