如何隐藏TableViewCells?

b4qexyjb  于 2022-10-23  发布在  Swift
关注(0)|答案(1)|浏览(100)

我有2个数组。

postList:[
    {id: 1, name: "json", content: "hi", sex: "male"},
    {id: 2, name: "bob", content: "hello", sex: "male"},
    {id: 3, name: "john", content: "wow", sex: "male"},
    {id: 3, name: "john", content: "unbelievable", sex: "male"}
    ]

blockList: [
    {id: 3, name: "john"},
    {id: 4, name: "allen"}
]

Tableview由postList数据组成。我希望如果lockList.id==postList.id,单元格应该被隐藏。如何比较2个数组和隐藏单元格?

xdnvmnnf

xdnvmnnf1#

@hor比较数据数组并创建结果数组
然后使用结果数组将数据设置到表视图
请参阅以下内容:

let filteredList = postList.filter { dict in
    !blockList.contains(where: { blockDict in
        return dict["id"] as? Int == blockDict["id"] as? Int
    })
}

print(filteredList.map({ $0["name"] as? String }))

在上面的示例中,您可以使用filteredArray将数据设置到您的表视图中

相关问题