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

问题描述

我有一个自定义列表,用于显示领域数据库中的值,但是每当我在列表上配置 .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()
            }
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)