SwiftUI NavigationBarItems slideBack冻结应用程序

问题描述 投票:2回答:1

我的HomeView(我在其中存储Movies的列表)具有NavigationViewNavigationLink,目的地为DetailView

当我想在我的NavigationBarItems中添加DetailView时,它使我的后退幻灯片(从DetailViewHomeView)无效。当我停止在屏幕的约1/3处滑动时,该应用程序冻结。

我在NavigationView中没有额外的DetailView,因为当我拥有它时,我在DetailView中将其加倍。

[我发现破坏所有内容的代码行。

NavigationBarItems的一部分:

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

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)
            }
        }
    }
}
ios swiftui navigationbar back-button
1个回答
0
投票

这是SwiftUI的错误。如果删除.sheet中的HomeView,它将按预期运行,而不会冻结应用程序。

如果您同时具有.alert,似乎也会发生同样的事情。

© www.soinside.com 2019 - 2024. All rights reserved.