ios - 如何通过 2 个不同的按钮过滤 TableView 输出?

标签 ios swift uitableview

我正在处理如下所示的 TableView : enter image description here

我在互联网上查看,但所有信息都是关于搜索栏的,我不想要搜索栏,只想要两个选项 - 已接种疫苗和未接种疫苗。我该怎么做才能按他们过滤表格?

最佳答案

你应该有 2 个数组

var allData = [Model]()
var filteredData = [Model]()

struct Model {
 var vaccinated:Bool
}

当按钮被点击时

 filteredData = allData.filter { $0.vaccinated } // or !$0.vaccinated for the second option
 tableView.reloadData()

关于ios - 如何通过 2 个不同的按钮过滤 TableView 输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59524376/

相关文章:

ios - Alamofire 4.7 中的自定义 SessionManager 立即取消

ios - 通过 Cocoapods 包含 Xcode 7 UI 测试依赖项?

ios - usleep 在 iOS 中不起作用

iphone - UITableView 单元格采用 UITableView 背景图像的图案颜色

ios - 如何删除 UITableView NSAutoresizingMaskLayoutConstraint?

ios - 如何获取 iOS 移动配置文件的代码签名证书

ios - 如何得到类似苹果 map 状态栏的模糊效果?

ios - 更新到 Swift 2.0 'map' 不可用 : call the 'map()' method on the sequence

ios - JSON解析数据没有被调用? swift

ios - Swift - 随 UITextView 一起增长的静态 UITableView