0

I know this is a startlingly stupid question, but I can't figure it out. Every answer involves a UISearchBar, which is not what I've got.

I'm trying to display 2 sets of results on one TableViewController.

Results to display

1) everything in my managedObjectContext which is set up in my viewDidLoad

2) a filtered set of results if a predicate is selected.

On MyTableViewController, I have a popover which instantiates when I click a UIBarButtonItem on MyTableViewController. On the popover, I set a predicate on MyTableViewController.

Basically, I'd like to toggle what's displayed and that display toggle is driven by whether my variable is nil (everything displays) or filtered (variable sets a predicate).

Adrian
  • 16,233
  • 18
  • 112
  • 180
  • Did you have a question? – Hot Licks Apr 25 '15 at 18:17
  • What you've written is more of a specification than a question. It seems to me to be just a case of selecting the correct data source, either one that represents everything or one that only contains your selected subset of items. – Phillip Mills Apr 25 '15 at 18:18
  • I wrote a detailed question, but I'm not getting anything back. Above is the "physics for poets" version. Here's everything. http://stackoverflow.com/questions/29856403/uitableview-not-refreshing-despite-not-crashing-nslog-values-printing-properl – Adrian Apr 25 '15 at 18:20
  • 1
    You can add something like this. Take a BOOL isSearchOn variable type and make it YES whenever your searchbar has some text.. In cellForRowAtIndex method just do if(isSearchOn){} else {}. Same for number of rows or sections – Rajan Maheshwari Apr 25 '15 at 18:34

1 Answers1

1

Have two NSArray properties allValues and filteredValues. Set up all your delegate/dataSource properties using your filteredValues array.

Next, do something like this when you first get all your data:

self.allValues = [someController fetchAllValues];
self.filteredValues = self.allValues;
[self.myView.tableView reloadData];

Last, alter your filteredValues array whether or not a predicate is selected:

if (self.selectedPredicate) {
    self.filteredValues = [self.allValues filteredArrayUsingPredicate:self.selectedPredicate];
} else {
    self.filteredValues = self.allValues;
}
[self.myView.tableView reloadData];
Rufel
  • 2,630
  • 17
  • 15