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

Ribbit iOS Version Issue (Displaying Our List of Friends)

Hey guys,

I've come across a weird problem that is bugging me. Basically I have followed along with the video fine and the app runs with no errors. I go and tap on the "Friends" tab and in the video Ben Jakuben will tap on friends and all of his friends will only show up "Amit" and "Pasan" will display. I do the same as what Ben demonstrated except I get "Amit", "Pasan" and "Stu", Stu being me. Is the app meant to do this or have I missed something? I have included FriendsViewController.m as well as the accompanying header file.

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface FriendsViewController : UITableViewController

@property (nonatomic, strong) PFRelation *friendsRelation;
@property (nonatomic, strong) NSArray *friends;

@end
#import "FriendsViewController.h"

@implementation FriendsViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
    PFQuery *query = [self.friendsRelation query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else {
            self.friends = objects;
            [self.tableView reloadData];
        }
    }];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.friends count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    PFUser *user = [self.friends objectAtIndex:indexPath.row];
    cell.textLabel.text = user.username;

    return cell;
}

@end

Thanks but this is kind of bugging me as I know that's not how it's meant to be.

Stu :)

3 Answers

If you're friends with yourself that's exactly what will happen, yes.

Jens Hagfeldt
Jens Hagfeldt
16,548 Points

I hade the same problem earlier but have now solved it. When I was about to hook up the Friends scene in the storyboard I should have selected the class FriendsTableViewController in the Identity Inspector. But I made the mistake to instead connect it to the wrong class (EditFriendsViewController), probably because of the quite similar names. Check to see if you might have made the same misstake as me.

I found the answer that worked for me.... check the very bottom of your friendsViewController, it seems you are missing some code:

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. }

once I added this to my friendsViewController the friends list populated. hope this helps