Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
swift使用领域中的数据过滤_Swift_Search_Realm - Fatal编程技术网

swift使用领域中的数据过滤

swift使用领域中的数据过滤,swift,search,realm,Swift,Search,Realm,在我的应用程序中,我正在使用jSONData并将其存储到领域中。我使用了UISegmentedControl来显示三种类型的数据。例如:全部、已完成和未压缩。该应用程序还具有一个能够从UITableView中搜索数据的功能 //MARK: - SegmentButtonPressed @IBAction func segmentPressed(_ sender: UISegmentedControl) { let segmentTag = sender.selectedSegmentIn

在我的应用程序中,我正在使用
jSONData
并将其存储到
领域中。我使用了
UISegmentedControl
来显示三种类型的数据。例如:
全部、已完成和未压缩
。该应用程序还具有一个能够从UITableView中搜索数据的功能

//MARK: - SegmentButtonPressed
@IBAction func segmentPressed(_ sender: UISegmentedControl) {
    let segmentTag = sender.selectedSegmentIndex
    
    switch segmentTag {
    case 0:
        self.loadTodoList()
        print(1)
        
    case 1:
        print(3)
        todoLists = todoLists?.sorted(byKeyPath: "completed", ascending: false)
        todoListTable.reloadData()
     
    case 2:
        todoLists = todoLists?.sorted(byKeyPath: "completed", ascending: true)
           todoListTable.reloadData()
        print(2)
    
        
    default:
        print("none")
    }
}
UISearchBarDelegate

extension ViewController: UISearchBarDelegate {
    
    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        
        todoLists = todoLists?.filter("title BEGINSWITH [cd] %@", searchBar.text!).sorted(byKeyPath: "title", ascending: true)
        todoListTable.reloadData()
    }
    
    func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        if searchBar.text?.count == 0{
            loadTodoList()
            DispatchQueue.main.async {
                searchBar.resignFirstResponder()
            }
        }
    }
}

当用户按下其中一个按钮时,我可以过滤数据。但是在选择了
All、Completed和uncompleted
其中任何一个之后,如何使用
ui搜索栏搜索数据并显示我的UiTableViewCell?提前谢谢。

我不太清楚你在问什么。您是在问如何过滤领域还是如何实现UISearchBar?switch语句是如何工作的?你希望分机做什么?另外,您如何知道您的对象是已完成还是未完成?请澄清问题,您可能希望包括您的领域对象,以便我们了解它的使用方式。