'SwiftUI [Presentation] Attempt to present ... on ... whose view is not in the window hierarchy
After adding .confirmationDialog to the "Cancel" Button, I get the following message in the console, when I click on "Discard Changes" Button:
[Presentation] Attempt to present <SwiftUI.PlatformAlertController: 0x1038c8000> on <TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView: 0x104c07850> (from <TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier_: 0x104c1b2b0>) whose view is not in the window hierarchy.
What does it mean? And is this something to worry about, or can I just ignore it? Please help
Here's my code:
import SwiftUI
struct DetailView: View {
@Binding var scrum: DailyScrum
@State private var data = DailyScrum.Data()
@State private var isPresentingEditView = false
@State private var isShowingConfirmationDialog = false
var body: some View {
List {
Section(header: Text("Meeting Info")) {
NavigationLink(destination: MeetingView()) {
Label("Start meeting", systemImage: "timer")
.font(.headline)
.foregroundColor(.accentColor)
}
HStack {
Label("Length", systemImage: "clock")
Spacer()
Text("\(scrum.lengthInMinutes) minutes")
}
.accessibilityElement(children: .combine)
HStack {
Label("Theme", systemImage: "paintpalette")
Spacer()
Text(scrum.theme.name)
.padding(4)
.foregroundColor(scrum.theme.accentColor)
.background(scrum.theme.mainColor)
.cornerRadius(4)
}
.accessibilityElement(children: .combine)
}
Section(header: Text("Attendees")) {
ForEach(scrum.attendees) { attendee in
Label(attendee.name, systemImage: "person")
}
}
Section("History") {
Label("No meetings yet", systemImage: "calendar.badge.clock")
}
}
.navigationTitle(scrum.title)
.toolbar {
Button("Edit") {
isPresentingEditView = true
data = scrum.data
}
}
.sheet(isPresented: $isPresentingEditView) {
NavigationView {
DetailEditView(data: $data)
.navigationTitle(Text("\(scrum.title)"))
.toolbar {
ToolbarItemGroup(placement: .cancellationAction) {
Button("Cancel") {
isShowingConfirmationDialog = true
}
.confirmationDialog(
"Are you sure you want to discard your changes?",
isPresented: $isShowingConfirmationDialog
) {
Button("Discard Changes", role: .destructive) {
isPresentingEditView = false
// Causes: [Presentation] Attempt to present <SwiftUI.PlatformAlertController: 0x1038c8000> on <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x104c07850> (from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVVS_22_VariadicView_Children7ElementVS_24NavigationColumnModifier__: 0x104c1b2b0>) whose view is not in the window hierarchy.
}
Button("Keep Editing", role: .cancel) {
isShowingConfirmationDialog = false
}
} message: {
Text("Are you sure you want to discard your changes?")
}
}
ToolbarItemGroup(placement: .confirmationAction) {
Button("Done") {
isPresentingEditView = false
scrum.update(from: data)
}
}
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
