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


Jason Brown
Jason Brown
3,379 Points

ios bug can't access the first cell in tableview

I’m done building the Self Destructing Messaging app (Yea!), but I have a bug (boo!) that I can’t figure out.

  1. If you have only 1 message in the inbox, you can tap it and it is highlighted, but it won’t open.

  2. If you have 2 or more messages in the inbox and you click on only one cell, it won’t open, but if you click on two cells (they both highlight) and then one message opens.

Here are screenshots of the bug in action:


Any help is greatly appreciated!

Jason Brown
Jason Brown
3,379 Points

Here is my code for InboxTableViewController:

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {

    self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
    NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
    if ([fileType isEqualToString:@"image"]) {
        [self performSegueWithIdentifier:@"showImage" sender:self];
    else {
        PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
        NSURL *fileUrl  = [NSURL URLWithString:videoFile.url];
        self.moviePlayer.contentURL = fileUrl;
        [self.moviePlayer prepareToPlay];

        //display thumbnail
        AVAsset *videoThumbnail = [AVAsset assetWithURL:fileUrl];
        [AVAssetImageGenerator assetImageGeneratorWithAsset:videoThumbnail];

        //add it to the view controller so we can see it
        [self.view addSubview:self.moviePlayer.view];
        [self.moviePlayer setFullscreen:YES animated:YES]; 

    //Delete Message
    NSMutableArray *recipientIds = [NSMutableArray arrayWithArray:[self.selectedMessage objectForKey:@"recipientIds"]];
    NSLog(@"Recipients %@",recipientIds);

    if ([recipientIds count]==1) {
        //last recipient DELETE!
        [self.selectedMessage deleteInBackground];
    else {
        //remove recipient and save it
        [recipientIds removeObject:[[PFUser currentUser]objectId]];
        [self.selectedMessage setObject:recipientIds forKey:@"recipientIds"];
        [self.selectedMessage saveInBackground];


1 Answer

Hey your method.. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {

Any chance it is actually meant to be "didSelectRowAtIndexPath" instead ?

Jason Brown
Jason Brown
3,379 Points

Nice work Alex! I can't believe I couldn't find that. I really appreciate the help.

Problem solved.

No problem jason! Happy to help! Best of luck in your studies!

Very common error. I think we've all done it once, but you know in the future not to do it again, so be happy you made the mistake!