SwiftUI 导致 AttributeGraph 前提条件失败:属性值类型无效:列表中的 54808

时间:2021-07-18 06:31:08

标签: swiftui swiftui-list

我有一个自定义列表,用于显示领域数据库中的值,但是每当我在列表上配置 .sheet 属性时,只要用户点击该行就会显示工作表。但是,每当我添加 .sheet 时,应用程序都会立即崩溃,导致以下错误:

2021-07-18 11:56:15.978645+0530 mongodb-swiftui[21360:965109] [error] precondition failure: invalid value type for attribute: 54808 (saw ListView, expected PreferenceKeys)
CoreSimulator 772.1 - Device: iPhone 12 Pro (A078F6C3-6036-4065-93D4-01495735E0FA) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12 Pro
AttributeGraph precondition failure: invalid value type for attribute: 54808 (saw ListView, expected PreferenceKeys).
(lldb) 

这是我设计的自定义列表代码:

import SwiftUI

struct ListView: View {
    
    @State var date:String?
    @State var title:String?
    @State var mood:String?
    @State var isOpen: Bool = false
    
    var body: some View {
        ZStack {
            RoundedRectangle(cornerRadius: 25, style: .continuous)
                .fill(Color.gray)
            HStack {
                VStack(alignment: .leading){
                    Spacer()
                    Text(date!)
                        .foregroundColor(.black)
                    Text(title!)
                        .foregroundColor(.black)
                        .font(.title)
                    Text(mood!)
                        .font(.title2)
                        .foregroundColor(.white)
                    Spacer()
                }
                .padding()
                Spacer()
                Text("Info")
                    .foregroundColor(.blue)
                    .onTapGesture {
                        isOpen.toggle()
                    }
                Spacer()
                
            }
            .sheet(isPresented: $isOpen){
                LoginView()
            }
        }
    }
}

0 个答案:

没有答案