以下代码以 2 种方式呈现相同的视图 PatientView:
- 作为一张纸
- 导航链接
var body: some View {
NavigationView {
List {
ForEach(patients, id: \.self) { patient in
NavigationLink(destination:
PatientView(selectedPatient: patient, isDependant: false, mainID: "")) {
PatientRowView(patient: patient)
}
}
.onDelete { indexSet in
for index in indexSet {
self.moc.delete(self.patients[index])
}
}
}
.navigationBarItems(trailing: Button(action: {
self.showingAddScreen.toggle()
}) {
Image(systemName: "plus")
})
.sheet(isPresented: $showingAddScreen) {
PatientView(selectedPatient: nil, isDependant: false, mainID: "").environment(\.managedObjectContext, self.moc)
}
.navigationBarTitle("Patients")
.background(NavigationConfigurator { nc in
nc.navigationBar.barTintColor = .launchpadBackgroundGray
nc.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.black]
})
}
}
当显示为工作表时,PatientView 上的选择器被禁用:
但是当通过 Navigationlink 呈现时,选择器按预期工作:
有谁知道为什么会这样?当以表格形式呈现时,任何使选择器正确的解决方案将不胜感激。
谢谢你