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

iOS

PLEASE Help! Search Feature For Ribbit

I almost got the search for friends feature in Ribbit working. I did some of the coding from this post:

https://teamtreehouse.com/forum/adding-search-friends-to-ribbit

  1. I changed this code in EditFriendsViewController.m:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {
            self.allUsers = nil; <<MADE THIS NIL
            [self.tableView reloadData];
  1. I added this to the .m as well. I added @property (nonatomic, strong) PFUser *user; to the .h
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.user) {       
        //a user was found, we need to display one row.

        return 1;
    }

    else {    
        //a user was not found/searched for yet, dont display any rows

        return 0;
    }
    // Return the number of rows in the section.

    return [self.allUsers count];
}

Everything is added and there are no issues in Xcode but the search isn't showing someone when I type in their name and hit search...any suggestions?

2 Answers

when the query finds a user, you need to set your user property as the user that was returned by the query

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
        else {
           //set your user property to the first (and only) object in the objects array
self.user = [objects objectAtIndex:0];
[self.tableView reloadData];

}

you also need to update your cellForRowAtIndexPath to use your new user property as its data. so inside cellForRowAtIndexPath you need to make sure you set the text label using the user username.

cell.textLabel.text = self.user.username;

Thank you! I've been able to add everything!

In the simulator it when I press search it won't show any users, it that only because its not a actual device?

So I guess I never connected the search bar property to the search bar and the search bar started working. But when I search for a person nothing comes up?

have you changed the data source for your tableview to self.user for numberOfRowsInSection and cellForRowAtIndexPath ?