【问题标题】:Double List in NavigationView [Swift]NavigationView [Swift] 中的双重列表
【发布时间】:2020-08-25 14:59:20
【问题描述】:

我正在尝试将项目的两个类别放在两个不同的列表中,分别名为“Wide-Field”和“Deep-Sky”,但我希望第二个列表低于第一个.

期待它看起来像这样:

但是,相反,它将屏幕分成两半,我得到了这个结果:

我当前的代码:

import SwiftUI

struct ListView: View {
    @Environment(\.colorScheme) var colorScheme

    var body: some View {
        NavigationView {
            VStack {
                List {
                    ForEach(Photographs.wideFieldPhotos, id: \.self) { key in
                        HStack {
                            PhotographRow(photo: key)
                        }
                    }
                }
                .navigationBarTitle("Wide-Field")
                List {
                    ForEach(Photographs.deepSkyPhotos, id: \.self) { key in
                        HStack {
                            PhotographRow(photo: key)
                        }
                    }
                }
                .navigationBarTitle("Deep-Sky")
            }
        }
    }
}

struct ListView_Previews: PreviewProvider {
    static var previews: some View {
        ListView()
    }
}

【问题讨论】:

    标签: swift swiftui vstack ios-navigationview swiftui-navigationview


    【解决方案1】:

    我假设你想要 一个 列表与 两个 部分,如

    var body: some View {
        NavigationView {
            List {
                Section(header: Text("Wide-Field").font(.largeTitle)) {
                    ForEach(Photographs.wideFieldPhotos, id: \.self) { key in
                        HStack {
                            PhotographRow(photo: key)
                        }
                    }
                }
    
                Section(header: Text("Deep-Sky").font(.largeTitle)) {
                    ForEach(Photographs.deepSkyPhotos, id: \.self) { key in
                        HStack {
                            PhotographRow(photo: key)
                        }
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-18
      • 1970-01-01
      • 2019-06-03
      • 2018-04-07
      • 1970-01-01
      • 2020-05-12
      • 2018-02-09
      • 2013-07-18
      相关资源
      最近更新 更多