我的HomeView(我存储列表的位置Movies)有NavigationView和NavigationLink目的地为DetailView。
当我想添加NavigationBarItems我的时DetailView,它使我的GoBack Slide(从DetailView到HomeView)毫无用处。当我停止在屏幕的 1/3 处滑动时,应用程序冻结。
我没有额外NavigationView的DetailView,因为当我拥有它时,我把它加倍了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 …Run Code Online (Sandbox Code Playgroud) 我正在使用 SwiftUI 学习核心数据。我想制作一个应用程序,我可以在其中发布我喜欢的电影、进行评论并添加评分。
我已经可以在我的应用程序中添加新电影,将其删除,请参阅电影详细信息。现在我想在 CoreData 中编辑我的记录。我发现这很困难,因为我不知道如何将编辑好的电影中的默认值放置到我的表单中。
我的代码:
struct EditMovieVIew: View {
let movie: Movie
@Environment(\.presentationMode) var presentationMode
@Environment(\.managedObjectContext) var moc
@State private var title = ""
@State private var director = ""
@State private var review = ""
@State private var genre = "Fantasy"
@State private var rating = 3
@State private var productionYear = Date()
let genres = ["Sci-Fi","Fantasy", "Comedy", "Horror", "Thriller", "Criminal", "Kids", "Romance", "Drama"]
var body: some View {
NavigationView {
Form {
Section {
TextField("Name of …Run Code Online (Sandbox Code Playgroud)