views:

81

answers:

2

I have an iPhone app based on a tabBar and tableViews. I want the user to be able to click on one tab and access options for filtering the data in the initial tableView.

The problem I'm having is that while the user is selecting filter criteria, I want the main table (not visible) to update. The reason this is important is that I want to show how many cells are still in the table as it is being filtered in the navigation bar.

Currently, the method for filtering the main table (-handleFilter) is called in the viewWillAppear method of my rootViewController class. How can I call this method from my "searchOptions" class?

Thanks for the help!

+2  A: 

It sounds like you're conflating too much between your model and your controllers (assuming you're following the MVC design pattern). The other controllers besides the main table should be able to query the model themselves to display the count information without asking the main table controller.

I could be misunderstanding something though, a little more information on what data you're using and how it's being filtered in the controllers attached to the other tab bar items would help.

refulgentis
+1  A: 

The most straightforward way would be to give the options controller a pointer to the list controller. Then you can call the method directly.

Other options include defining a method/property on some global object (like your app delegate) to access the list controller from elsewhere in the app, and using a more decentralized mechanism like NSNotificationCenter to pass that information around (rather an a method call), or relying on the model itself to notify all of the controllers accessing it when it changes (possibly using Key-Value Observing, or an explicit delegate protocol).

Sixten Otto
How would you give the one controller a pointer to another?Thanks for the help!
Jonah
Define a property on your controller subclass to hold the reference, and set it when you're instantiating the controller. For example. (Note that this isn't necessarily the BEST option, but it is the straightest path to letting you call that method.)
Sixten Otto