我认识到,当我使用密封名单时,我看不到这些守则中的任何内容。 但是,当我删除名单时,我可以看到所有观点。 不幸的是,没有使用清单一,就无法使用清单一,这是一个问题。
struct ListsInfoView: View {
@Environment(.managedObjectContext) private var viewContext
@FetchRequest(entity:CDListModel.entity(),
sortDescriptors: [
NSSortDescriptor(
keyPath:CDListModel.title,
ascending: true )
]
)var lists: FetchedResults<CDListModel>
@State var isListSelected = false
@State var selectedList : CDListModel!
var body: some View {
List{
ForEach(lists) { list in
Button(action: {
self.selectedList = list
self.isListSelected.toggle()
}) {
ListCell(list: list)
}
}
.onDelete(perform: deleteList)
}
.listStyle(PlainListStyle())
.fullScreenCover(isPresented: $isListSelected) {
ListDetailView(selectedList: $selectedList)
.environment(.managedObjectContext, viewContext)
}
}
func deleteList(at offsets: IndexSet) {
viewContext.delete(lists[offsets.first!])
PersistenceController.shared.saveContext()
}
}
和以上情况一样,我看不见任何名单Cell,但当我删除名单{}时,名单是完美的。 为什么如此?
My ListCell
struct ListCell: View {
@ObservedObject var list : CDListModel
var body: some View {
HStack{
Image(systemName: "folder")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 30, height: 30, alignment: .center)
.foregroundColor(.yellow)
Text(list.title ?? "")
.foregroundColor(.black)
.font(.system(size: 20, weight: .regular, design: .rounded))
.padding(.leading,10)
Spacer()
Text(String(list.notes?.count ?? 0))
.foregroundColor(.gray)
Image(systemName: "chevron.right")
.foregroundColor(.gray)
}
.padding(.horizontal)
}
}
这就是我所说的话。 在《名单》中,我是《名单》。
struct MainView: View {
@Environment(.managedObjectContext) private var viewContext
@State var searchText = ""
@State var newFolderName = ""
@State var isAddList : Bool = false
@State var isAddNote: Bool = false
var body: some View {
ZStack{
Color(.white)
.edgesIgnoringSafeArea(.all)
NavigationView{
VStack(alignment: .leading){
ScrollView{
SearchBar(text: $searchText)
.environment(.managedObjectContext, viewContext)
ListsView()
.environment(.managedObjectContext, viewContext)
名单
struct ListsView: View {
@Environment(.managedObjectContext) private var viewContext
@State var isShowTapped: Bool = false
@State var selectedIndex : Int = 0
var body: some View {
VStack {
Spacer()
HStack{
Text("On My iPhone")
.font(.system(size: 20, weight: .semibold, design: .rounded))
Spacer()
Button(action: {
withAnimation{
self.isShowTapped.toggle()
print("slider button tapped")
}
}, label: {
Image(systemName:isShowTapped ? "chevron.down" : "chevron.right")
.foregroundColor(.black)
})
}
.padding(.horizontal)
if isShowTapped {
ListsInfoView()
.environment(.managedObjectContext, viewContext)
.transition(.scale)
} else {}
Spacer()
}
}
}