如何在 Mac 上处理 SwiftUI 表中的动态列名称
我有一个 SwiftUI 表,需要根据来自服务器的一些请求数据进行布局。该数据是动态的并且会变化。但是,一旦我将这些数据读入数组,它就不允许我对列数据执行 forEach,因为它不符合“TableColumnContent”。是否有另一种方法来循环此创建,或者是否有一种简单的方法来符合此协议?当我查看该协议时,我很难理解它。
struct DataProperty : Identifiable
{
var id: String
var name: String
}
struct TableDataView : View
{
@EnvironmentObject var cache: ServerCache
var body: some View
{
Table(cache.activeTableData)
{
ForEach(cache.activeProperties, id: \.self) {property in
TableColumn(property.name, value: \.id)
}
}
}
}
请注意,activeProperties 是 DataProperty 的数组。我在这里做错了什么?
I have a SwiftUI table that I need to layout based on some request data from a server. This data is dynamic and changes. However, once I read this data into an array, it will not allow me to do a forEach on the column data, as it companies about not conforming to "TableColumnContent". Is there another way to loop this creation, or is there a simple way to conform to this protocol? I am having trouble understanding that protocol when I look at it.
struct DataProperty : Identifiable
{
var id: String
var name: String
}
struct TableDataView : View
{
@EnvironmentObject var cache: ServerCache
var body: some View
{
Table(cache.activeTableData)
{
ForEach(cache.activeProperties, id: \.self) {property in
TableColumn(property.name, value: \.id)
}
}
}
}
Note that activeProperties is an array of DataProperty. What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论