【发布时间】:2019-11-07 20:50:23
【问题描述】:
尝试制作类似于 Apple 日历应用中的“创建事件”模式的模式。我已经在父 NavigationView 中使用以下代码成功显示了我的模式:
.navigationBarItems(trailing:
Button(action: {
self.isModal = true
}) {
Image(systemName: "plus").sheet(isPresented: $isModal, content: {
EventCreate(showModal: self.$isModal)
})
}
)
模态显示成功,但我无法在模态中显示 NavigationBar,如下所示:
struct EventCreate: View {
@Binding var showModal: Bool
@State var event = Event(id: 0, title: "", description: "", location: "", start: Date(), end: Date(), cancelled: false, public_occurrence: false, created: "", last_updated: "", guests: -1)
var body: some View {
NavigationView {
Form{
Section {
TextField("Title", text: $event.title)
TextField("Location", text: $event.location)
}
Section {
DatePicker(selection: $event.start, label: { Text("Start") })
DatePicker(selection: $event.end, label: { Text("End") })
}
}
}
.navigationBarTitle(Text("Create Event"), displayMode: .inline)
.navigationBarItems(leading:
Button("Close") {
self.showModal = false
})
}
}
应用程序构建,并显示窗体,但 NavigationView 没有:
如何制作这个节目?或者我应该使用另一个视图来代替 NavigationView
【问题讨论】: