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

Ribbit app has problems.

The ribbit app in the iOS development section has lots of issues. Like in the EditFriendsViewController when they say [self.tableView deselectRowAtIndex:indexPath]; the following code does not work properly in the iOS7 it still keeps the cell in the blue color after clicking it... If you guys know how to fix this bug then please feel free to comment...

Holger Liesegang i just spotted that as you posted. Sai Kiran Dasika observe Holger's answer. Try using deselectRowAtIndexPath instead of deselectRowAtIndex

Okay thanks guys. :D

Did it work?

Yesss !! Its working for me. :D thanks Holger. Yes scott it is working for me...

Holger Liesegang can you move your comment to answer,s so we can provide it with a best answer :D

Thank you, Scott Evans - being Moderator has it merits :)

Holger Liesegang sent you a mail, and deleted the previous posts.

http://teamtreehouse.com/holgerliesegang it did not work... :( it is still having that blue thing on the cell.

I'm sorry to hear that - what changed? When does it stop working? May I ask you to post a photo of the incident ("that blue thing on the cell") and the code, please.

Here you go this is the code...

@interface PTEditFriendsViewController ()

@end

@implementation PTEditFriendsViewController



- (void)viewDidLoad
{
    [super viewDidLoad];

    PFQuery *query = [PFUser query];
    [query orderByAscending:@"username"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (error) {
            NSLog(@"%@ %@",error, [error userInfo]);
        }
        else {
            self.allUsers = objects;
            [self.tableView reloadData];
            NSLog(@"%@",self.allUsers);
        }
    }];
    self.currentUser = [PFUser currentUser];
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // 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;

    if([self isFriend:user]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    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]);
        }
    }];
}

-(BOOL)isFriend:(PFUser *)user {
    for (PFUser *friend in self.friends) {
        if ([friend.objectId isEqualToString:user.objectId]) {
            return YES;
        }
    }
    return  NO;
}

@end

4 Answers

Hi Sai Kiran,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    PFRelation *friendsRelation = [self.currentUser relationforKey:@"friendsRelation"];
    PFUser *user = [self.allUsers objectAtIndex:indexPath.row];

    if ([self isFriend:user]) {
        cell.accessoryType = UITableViewCellAccessoryNone;

        for(PFUser *friend in self.friends) {
            if ([friend.objectId isEqualToString:user.objectId]) {
                [self.friends removeObject:friend];
                break;
            }
        }

        [friendsRelation removeObject:user];
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        [self.friends addObject:user];
        [friendsRelation addObject:user];
    }

    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error: %@ %@", error, [error userInfo]);
        }
    }];
}

should work just fine with iOS 7.1 as IMHO there doesn't seem to be any deprecated parts in it.

To the topic starter : I just had the same problem. The problem is that you have put in inside : didDeselectRowAtIndexPath but it should be inside : didSelectRowAtIndexPath

notice the difference, "didDeselectRowAtIndexPath" comes up in Xcode autocomplete before "didSelectRowAtIndexPath"

As far as i know know there might be slight differences in the SDK. I think Ribbit was built on iOS 6, whereas now were are on 7. Some things may have been depreciated or changed.

Im not 100% sure about this hence why i tagged the teachers as they will know far more.

Ok thanks. Do u know any way how to reach them ?

Ive tagged them in the post, they will post when and if they get chance.

Id suggest researching the code that your having problems with in the mean time to see if anything was changed or depreciated.

Okay ! So they will see the tags. Thanks for your time Scott :D

Hey I figured out the answer if anyone was still wondering or has not yet got it.

When you call the following method [self.tableView deselctRowAtIndexPath:indexPath animated:No];

In iOS 7 you can not state self for this call. It holds the highlight. if you remove the self and only call tableView then the method it will work fine