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 Build a Self-Destructing Message iPhone App Relating Users in Parse.com Adding the Edit Friends Screen

Relations User in Parse.com

Hey Guy!! I am trying to follow the Relating Users in Parse.com video. I did all that Ben said and I did not find any failed although I can not see my friends in any list.

What can be wrong in this code?

// // EditFriendsTableViewController.h // Ribbit // // Created by mlabarga on 31/07/14. // Copyright (c) 2014 mayte. All rights reserved. //

import <UIKit/UIKit.h>

import <Parse/Parse.h>

@interface EditFriendsTableViewController : UITableViewController

@property (nonatomic, strong) NSArray *allUsers; @property (nonatomic, strong) PFUser *currentUser;

@end

// // EditFriendsTableViewController.m // Ribbit // // Created by mlabarga on 31/07/14. // Copyright (c) 2014 mayte. All rights reserved. //

import "EditFriendsTableViewController.h"

import <Parse/Parse.h>

@interface EditFriendsTableViewController ()

@end

@implementation EditFriendsTableViewController

  • (void)viewDidLoad { [super viewDidLoad]; PFQuery *query =[PFUser query]; [query orderByAscending:@"username"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (error) { NSLog(@"Error: %@ %@",error, [error userInfo]); } else { self.allUsers = 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.allUsers count]; }

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

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

pragma mark - Table view delegate

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryType = UITableViewCellAccessoryCheckmark;

    PFRelation *friendsRelation = [self.currentUser relationForKey:@"friendsRelation"]; PFUser *user = [self.allUsers objectAtIndex:indexPath.row]; [friendsRelation addObject:user]; [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { if (error) { NSLog(@"Error: %@ %@", error, [error userInfo]); } }];

}

@end

Thank you for your help!!! I am really frustrated

3 Answers

Hiya!

Do you see any potential friends when you click 'Edit Friends'? Are there some users to select?

If not, check Parse - are they there?

If you have selected some friends but can't see them on your Friends list, let's look at your FriendsViewController files.

Steve.

Hi Steve. Thank you so much for your help. At the end, you are right. I had a problem with Friends. I was writing "Cell" twice (in friends and edit friends.

Once again, thanks. Have a nice day.

Glad you got it sorted!! ;-)