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 Friends by Tapping on a Table View Cell

When I run the code from this video i get blank space in the LOG. where NSLog is supposed to post an error with username

import "EditFriendsTableViewController.h"

@interface EditFriendsTableViewController ()

@end

@implementation EditFriendsTableViewController

  • (void)viewDidLoad { [super viewDidLoad];

    PFQuery *query = [PFQuery queryWithClassName:@"User"]; [query orderByAscending:@"username"]; [query findObjectsInBackgroundWithBlock:^(NSArray *objects,NSError *error){

    if(error){
    
        NSLog(@"Error:%@ %@",error,[error userInfo]);
    }
    else
    {
        self.allUsers = objects;
        NSLog(@"%@",self.allUsers);
        [self.tableView reloadData];
    }
    

    }];

    self.currentUser =[PFUser currentUser];

}

  • (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }

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 { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

    // Configure the cell... PFUser *user = [self.allUsers objectAtIndex:indexPath.row]; cell.textLabel.text = user.username;

    return cell; }

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(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]);
    }
}];

}