我有一个数组值列表。每个对象都有一个 type
键值。所以在我的表格 View 中,我不应该显示特定类型的对象。以及我需要显示的所有其他对象。我该怎么做?
这是我的值(value)观:
(
{
"booking_id" = 1137;
"category_id" = 6;
"category_name" = Public;
type = Public;
},
{
"booking_id" = 1179;
"category_id" = 1;
"category_name" = bay range;
type = Offerers;
},
{
"booking_id" = 1178;
"category_id" = 1;
"category_name" = newYork range;
type = Offerers;
},
{
"booking_id" = 1137;
"category_id" = 6;
"category_name" = Public range;
type = Public;
}
)
如上。在我的表格 View 中,上面的值。我不应该显示 type == "public
"。所以我需要在表格 View 中显示所有其他值。我该怎么做。
我尝试检查类型 == “public”。但不确定如何从那里继续。
任何解决方案都会有所帮助。
谢谢。
更新:我也试过下面的代码。但它确实有效。
var detailsarr = NSMutableArray()
var dic = self.detailsarr.object(at: indexPath.section) as! NSArray;
我正在做这样的事情:
dic = dic.filter { $0["type"] != "Public" }
最佳答案
我相信您需要不显示 type = public 的数据的功能
从枚举开始,
枚举类型数据{
案例公开
案例提供者
}
定义模型
struct ModelData : Codable {
var booking_id, category_id : Int
var category_name : String
var type : TypeDta
}
然后在tableviewcontroller中
var rootData : [ModelData] {
didSet {tableViewDataSource = rootData.filter{$0.type != .public}}
}
这将是 numberOfRows 和 cellForRowAt 的数据源
var tableViewDataSource : [ModelData] = []()
然后调用tableView.reloadData()
关于ios - 将特定类型的数据显示到 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55227356/