Is it possible to nest filters using scope bars?

I have a tableview with a search bar and scope bar beneath. When the user choses an option from the scope bar, I want to reload the tableview with the filtered items, change the scope bar, and then refilter given choices from the new scope bar. It is easy enough to do the first two parts,

 

    func filterContentForSearchText(_ searchText: String, scope: String = “All”) {

        tfilteredPlants = trees.filter({( plant : Plant) -> Bool in

            let doesTreeMatch = (scope == “All”) || (plant.TreeShrub == scope)

            if searchBarIsEmpty() {

                return doesTreeMatch

            } else {

                return doesTreeMatch && plant.commonName.lowercased().contains(searchText.lowercased())

            }

        })

        if scope == “Shrub” {

            print(“Shrub”)

            treeSearchController.searchBar.scopeButtonTitles = [“All Leaf Types”, “Simple”, “Compound”]

        }

        tableView.reloadData()

    }

 

But now I want to match a different variable, call it Leaf, based on Compound or Simple being chosen, And I would like to filter again based on that. I could add a sequence of view controllers and segue between them, which would be messy but possible, but I was wondering whether there was a more compact approach.

Powered by WPeMatico

About

You may also like...

Comments are closed.