Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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]);
    }
}];

}