SwiftUI列表使用.navigationBarItems剪辑

时间:2020-11-12 16:57:59

标签: swiftui

当我添加.navigationBarItems修改器列表时,它会被裁剪并且不会占用所有空间https://docs.djangoproject.com/en/2.0/ref/urls/#path

应该类似于这张照片(没有.navigationBarItems): enter image description here

代码

struct PatientsListView: View {
    @ObservedObject var listData = PatientsListViewModel()
    var body: some View {
        NavigationView{
            Group {
                if listData.patientsList.count > 0{
                    List{
                        ForEach(Array(listData.patientsList)) {  patient in
                            NavigationLink(destination: PatientsDetailView(patient: patient),
                                           label: {
                                            PatientsListRow(patient: patient)
                                           })
                        }
                    }
                }
                else if listData.patientsList.count == 0 {
                    Text("Самое время добавить пациентов!").foregroundColor(.gray)
                    
                }
                else if listData.isLoading {
                    ProgressView()
                }
            }
            .navigationTitle("Пациенты")
            .navigationBarTitleDisplayMode(.large)
            .navigationBarItems(trailing: NavigationLink(destination: PatientCreateView(), label: {
                Image(systemName: "plus").foregroundColor(.white)
            }))
            
            
            
        }
        .onAppear(perform: {
            listData.fetchPatients()
        })
    }
}

1 个答案:

答案 0 :(得分:2)

这是默认行为。如果愿意,您可以明确设置列表样式,例如

List{
    ForEach(Array(listData.patientsList)) {  patient in
        NavigationLink(destination: PatientsDetailView(patient: patient),
                       label: {
                        PatientsListRow(patient: patient)
                       })
    }
}
.listStyle(PlainListStyle())        // << here !!