【发布时间】:2021-03-07 13:16:41
【问题描述】:
我有以下可识别的数据。我想要做的是我想添加view 的type,以便稍后我可以提供一个链接到这些视图的Button。我不知道如何做到这一点。它说它不接受视图类型。
我的目标是创建卡片,每张卡片都包含Datum 值。我想为每个人设置一个Button,将用户带到该特定视图。由于我做了一个ForEach,我希望能够添加每个Datum 的视图。我做了以下但swift不接受并抛出错误。
代码如下:
struct Datum:Identifiable {
var id = UUID()
var subtitle:String
var name:String
var footnote: String
var description:String
var image:String
var categoryTag:String
var comingSoon:Bool
//var modelName: **View**
}
public var categoriesList = ["DL", "TSA", "NLP"]
var ModelsData:[Datum] = [
Datum(subtitle: "Deep Learning",
name: "Mask Detection",
footnote: "An image classificaton model.",
description: "This model classifies whether a person has a mask or not. You simply take your camera and then take your face. Then, it will go and scan it. After that, you will see that at the bottom it shows green (means you have a mask) or red (which means you dont have a mask.)",
image: "MaskDetectionImage",
categoryTag: "DL",
comingSoon: false,
//modelName: MaskDetectionView()), //I want to add a view
Datum(subtitle: "Deep Leaning",
name: "Video games",
footnote: "An image classificaton app",
description: "This model classifies whether a person has a mask or not. You simply take your camera and then take your face. Then, it will go and scan it. After that, you will see that at the bottom it shows green (means you have a mask) or red (which means you dont have a mask.)",
image: "latest_1",
categoryTag: "DL",
comingSoon: false,
//modelName: ContentView())] //Another different view
这是图片:
【问题讨论】:
-
换个方式试试。而不是让 Datum 的实例拥有一个 View 属性;创建您的 SwiftUI 卡片视图以将 Datum 的实例作为属性保存。
-
你能告诉我怎么做吗?
标签: ios swift uiview swiftui identifiable