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

Jonathan Fernandez
Jonathan Fernandez
8,325 Points

accessoryType won't work for me

I'm trying to understand why this code won't compile in the compiler. Basically Xcode will not recognize accessoryType. (Although it seems to accept cell as a variable) Shown below is my code. I'll include everything up to the import statements as there might be an import I'm missing. (Although I think it more or less has to do with the version difference of my Xcode. I mean the method used is not even present anymore in new TableViewController templates)

Method that won't work is found at end of code please read comments. : )

<p>
#import "JWFEditFriendsTableViewController.h"
#import <Parse/Parse.h>

@interface JWFEditFriendsTableViewController ()

@end

@implementation JWFEditFriendsTableViewController


- (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 sections.
    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;
}


//This meathod was added in by me as it is no longer automatically added in this version of Xcode. Version: 5.1.1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableView *cell = [tableView cellForRowAtIndexPath:indexPath];
   cell.accessoryType = UITableViewCellAccessoryCheckmark; //This is the line of text that won't work.
}

</p>

I'm doing exactly as he's doing in the video and I'm going crazy right now trying to google any answers I can find haha. Any help will be greatly appreciated from you guys. : )

1 Answer

Stone Preston
Stone Preston
42,016 Points

in your didSelectRowAtIndexpath method you need to use UITableViewCell *cell, not UITableView *cell

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   cell.accessoryType = UITableViewCellAccessoryCheckmark; //This is the line of text that won't work.
}

this is what you currently have which is why its not working.

 UITableView *cell = [tableView cellForRowAtIndexPath:indexPath];
Jonathan Fernandez
Jonathan Fernandez
8,325 Points

Omg Thank you so much!!.. I feel so silly now not even noticing this!! Been cramming a lot of hours and think I need to go outside haha. Once again thanks. : )