Заголовок и элементы навигационной панели SwiftUI не исчезают при сбое считывания - PullRequest
2 голосов
/ 28 марта 2020

enter image description here

Проблема в том, что заголовок и элемент панели навигации не исчезают, что является неожиданным поведением.

struct DestinationView: View {

@State private var showingActionSheet = false

var body: some View {
    Text("DestinationView")
        .padding(.top, 100)
        .navigationBarTitle(Text("Destination"), displayMode: .inline)
        .navigationBarItems(trailing: Button(action: {
            print("tapped")
        }, label: {
            Text("second")
        }))
        .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
            ActionSheet(title: Text("Settings"), message: nil, buttons: [
                .default(Text("Delete"), action: {
                }),
                .cancel()
            ])
        }

}

}

1 Ответ

1 голос
/ 28 марта 2020

Проблема в том, что модификаторы .navigationBarTitle (), .navigationBarItems () и модификатор .actionSheet () находятся друг под другом в коде. (Но это могут быть модификаторы .alert () или .overlay (), а не .actionSheet ())

Решение в этом случае:

struct DestinationView: View {

@State private var showingActionSheet = false

var body: some View {

    List {
        Text("DestinationView")
            .padding(.top, 100)
            .navigationBarTitle(Text("Destination"), displayMode: .inline)
            .navigationBarItems(trailing: Button(action: {
                print("tapped")
            }, label: {
                Text("second")
            }))
    }
    .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
        ActionSheet(title: Text("Settings"), message: nil, buttons: [
            .default(Text("Delete"), action: {
            }),
            .cancel()
        ])
    }
}
}
...