Slavic the Slavic Slavic the Slavic - 3 years ago 115
iOS Question

How can you search through multiple views?

So I have an app with a table view, that has a search bar. The table view has listed categories that can be narrowed down through the use of the search bar (just basic filter functionality). When a category is clicked, it goes to another view controller that has a discription of that category. The discription is done in fully in storyboard using multiple labels.

My question is, how can I use the table view search not only to search through the categories, but to also search the words in the related view controllers?

Ex: The table view has 2 categories, Numbers, and Letters. When Numbers is clicked it goes to the view that says "1, 2, 3". When Letters is clicked it goes to the view that says "A, B, C". So in the table view when "1, 2" is entered, the table view would be filtered to only show the Numbers category.

I will provide code for my table view, and one related view controller if needed.

Any help would be greatly appreciated.

Answer Source

The view controllers are not initialized before you click on a category and then for example numbers. That means you can not search the views through the depending view controller.

This comes from breaking the mvc concept. You are holding data in a view. This is not correct.

You need to hold your data for the view in a model (a dictionary for example), so you can search over it in your table view.

As a bad approach, you could try to instantiate the view and the controller while searching. - through the storyboard file. But this feels very ugly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download