English 中文(简体)
清单
原标题:List ForEach Problem SwiftUI - ListCells are not visible with List

我认识到,当我使用密封名单时,我看不到这些守则中的任何内容。 但是,当我删除名单时,我可以看到所有观点。 不幸的是,没有使用清单一,就无法使用清单一,这是一个问题。

    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()
        }
    }
}
问题回答

图表 观点是问题。 GL!





相关问题
Finding a class within list

I have a class (Node) which has a property of SubNodes which is a List of the Node class I have a list of Nodes (of which each Node may or may not have a list of SubNodes within itself) I need to be ...

How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

Is List<> better than DataSet for UI Layer in ASP.Net?

I want to get data from my data access layer into my business layer, then prepare it for use in my UI. So i wonder: is it better to read my data by DataReader and use it to fill a List<BLClasses&...

What is the benefit to using List<T> over IEnumerable<T>?

or the other way around? I use generic lists all the time. But I hear occasionally about IEnumerables, too, and I honestly have no clue (today) what they are for and why I should use them. So, at ...

灵活性:在滚动之前显示错误的清单

我有一份清单,在你滚动之前没有显示任何物品,然后这些物品就显示。 是否有任何人知道如何解决这一问题? 我尝试了叫人名单。

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签