After writing a good run, the final simulator program only shows Goodone. Swift, a single module. The ContentView.swift content cannot be displayed. Unable to use the program properly. Need help
// goodone.swift
//
//
// Created by user on 2021/6/4.
//
import SwiftUI
struct goodone: View {
let coreDM: CoreDataManager
@State private var movieTitle: String = ""
@State private var movies: [Movie] = [Movie]()
@State private var needsRefresh: Bool = false
private func populateMovies(){
movies = coreDM.getAllMovie()
}
var body: some View {
NavigationView{
VStack {
TextField("输入待办事项", text: $movieTitle)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button("保存"){
coreDM.saveMovie(title: movieTitle)
populateMovies()
}
List {
ForEach(movies, id:\.self) { movie in
NavigationLink(
destination: MovieDetail(movie: movie, coreDM: coreDM, needsRefresh: $needsRefresh),
label: {
Text(movie.title ?? "")
})
}.onDelete(perform: { indexSet in
indexSet.forEach{ index in
let movie = movies[index]
//delete it using Core Data Manager
coreDM.deleteMovie(movie: movie)
populateMovies()
}
})
}.listStyle(PlainListStyle())
.accentColor(needsRefresh ?.white:.black)
Spacer()
}.padding()
.navigationTitle("待办事项")
.onAppear(perform: {
populateMovies()
})
}
}
}
struct goodone_Previews: PreviewProvider {
static var previews: some View {
goodone(coreDM: CoreDataManager())
}
}
// Main.swift
//
//
// Created by user on 2021/5/27.
//
import SwiftUI
struct Main: View {
var body: some View {
TabView{
goodone(coreDM: CoreDataManager())
.tabItem {
Image(systemName: "bolt.car")
Text("待办事项")
}.tag(1)
Text("车主信息")
.tabItem {
Image(systemName: "car.fill")
Text("车主信息")
}.tag(2)
Text("车主需求")
.tabItem {
Image(systemName: "person")
Text("车主需求")
}.tag(3)
Text("信息检索")
.tabItem {
Image(systemName: "simcard.2")
Text("信息检索")
}.tag(4)
}.accentColor(.red)
.font(.title3)
}
}
struct Main_Previews: PreviewProvider {
static var previews: some View {
Main()
}
}
// ContentView.swift
//
//
// Created by user on 2021/5/27.
//
import SwiftUI
struct ContentView: View {
var body: some View {
Main()
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}