SwiftUI NavigationBarItems SlideBack 冻结应用程序

Mac*_*kx7 5 back-button navigationbar ios swiftui

我的HomeView(我存储列表的位置Movies)有NavigationViewNavigationLink目的地为DetailView

当我想添加NavigationBarItems我的时DetailView,它使我的GoBack Slide(从DetailViewHomeView)毫无用处。当我停止在屏幕的 1/3 处滑动时,应用程序冻结。

我没有额外NavigationViewDetailView,因为当我拥有它时,我把它加倍了DetailView

我发现几行代码毁了一切。

它的一部分是NavigationBarItems

.navigationBarItems(trailing: Button(action: {
    self.showingEditScreen.toggle()
}) {
    Image(systemName: "pencil")
    .imageScale(.large)
    .accessibility(label: Text("Edit Movie"))
    .padding()
})
Run Code Online (Sandbox Code Playgroud)

HomeView

struct HomeView: View {
    @Environment(\.managedObjectContext) var moc

    @FetchRequest(entity: Movie.entity(), sortDescriptors: [
        NSSortDescriptor(keyPath: \Movie.title, ascending: true),
        NSSortDescriptor(keyPath: \Movie.director, ascending: true)
    ]) var movies: FetchedResults<Movie>

    @State private var showingAddScreen = false

    func deleteMovie(at offsets: IndexSet) {
        for offset in offsets {

            let movie = movies[offset]

            moc.delete(movie)
        }
        try? moc.save()
    }


    var body: some View {
        NavigationView {
            List {
                ForEach(movies, id: \.self) { movie in
                    NavigationLink(destination: DetailMovieView(movie: movie)) {
                        EmojiRatingView(rating: movie.rating)
                            .font(.largeTitle)
                        VStack(alignment: .leading) {
                            Text(movie.title ?? "Unknown Title")
                                .font(.headline)
                            Text(movie.director ?? "Unknown Director")
                                .foregroundColor(.secondary)
                        }
                    }
                }
                .onDelete(perform: deleteMovie)
            }
            .navigationBarTitle("Movie Store")
            .navigationBarItems(leading: EditButton(), trailing: Button(action: {
                self.showingAddScreen.toggle()
            }) {
                Image(systemName: "plus")
                    .imageScale(.large)
                    //.accessibility(label: Text("Add Movie"))
                    .padding()
            })
                .sheet(isPresented: $showingAddScreen) {
                    AddMovieView().environment(\.managedObjectContext,     self.moc)
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 3

目前这是 SwiftUI 的一个错误。如果您的 中有 a.sheet和/或 a ,请将其删除,它将按预期工作,而应用程序不会冻结。.alertDetailView