My HomeView
(我存储列表的地方Movies
) has NavigationView
and NavigationLink
目的地为DetailView
.
当我想添加的时候NavigationBarItems
in my DetailView
,它使我的返回幻灯片 (from DetailView
to HomeView
)没用。当我停止在屏幕的 1/3 处滑动时,应用程序冻结。
我没有额外的NavigationView
in DetailView
,因为当我拥有它时,我把它加倍了DetailView
.
我发现几行代码毁了一切。
它的一部分是NavigationBarItems
:
.navigationBarItems(trailing: Button(action: {
self.showingEditScreen.toggle()
}) {
Image(systemName: "pencil")
.imageScale(.large)
.accessibility(label: Text("Edit Movie"))
.padding()
})
And 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)
}
}
}
}
目前这是 SwiftUI 的一个错误。如果你有一个.sheet
和/或一个.alert
在你的DetailView
,删除它们,它将按预期工作,而应用程序不会冻结。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)