Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Dynamically filter app feed based on slide-out menu item selected

I have a prototype of an app that contains a feed UITableViewController.

The data to populate this feed comes from my model where I defined a Feed class that I pre-populate using the following data structure:

NSArray* data = @[@{const1:@"NSString1 for const1", const2:@"NSString1 for const2"},@{const1:@"NSString2 for const1", const2:@"NSString2 for const2"}, ..., @{const1:@"NSStringN for const1", const2:@"NSStringN for const2"}]; (total of N pairs of (const1, const2))

I created a slide-out menu view controller that is dynamically populated based on my data model as well. As such I defined a slideOutMenuItems class that I also pre-populate using the following data structure:

NSArray* data = @[@"MenuItem1", @"MenuItem2", @"MenuItem3",... @"MenuItemP"]; (Total of P menu items)

When a menu item is selected by the user from the slide-out menu, I want to dynamically pass the menu item string (@"MenuItemM" if row number M is tapped on by the user) to filter out my feed based on matching the const1 NSString component of my feed array with the @"MenuItemM" NSString.

For that, in my slide-out menu view controller, in the prepareforsegue method, I have attempted the following:

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Pass string based on SlideOutMenu cell selected to filter out feed

    if([segue.identifier isEqualToString:@"Filter_MenuItem"]) {
        FeedVCTableViewController* flameVCTableViewController = (FeedVCTableViewController*) segue.destinationViewController;
        NSIndexPath* indexPath = [self.tableView indexPathForCell:sender];
        NSString *menuItem = [self.slideOutMenuItems menuItemAtIndex:indexPath.row];
        NSPredicate *pred =[NSPredicate predicateWithFormat:@"name beginswith[c] %@", menuItem];
        flameVCTableViewController.feed = [[Feed prepopulatedFeed] filteredArrayUsingPredicate:pred];


But I get the following error message on the last line of code above:

"No visible @interface for Feed declares the selector filteredArrayUsingPredicate".