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

Eilon Krauthammer
Eilon Krauthammer
4,768 Points

Help in extra credit of stage 3 in the "Ribbit" app

I've added the new fields for firstname, last name etc in the sign up screen and connected it in my project and with Parse, and I've set up a new view controller and set my labels to the keys associated with Parse, and made a segue from the friends table view controller to the new view controller. I just don't know how to make it that when I press on a specific cell with a user on it to show the specific information to that user. Help please? :)

2 Answers

you can set up PFUser property in the profile view controller

@property (nonatomic, strong) PFUser *selectedUser;

then in the FriendsViewController, you can do something like this:

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

[self performSegueWithIdentifier:@“showProfile” sender:indexPath];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *indexPath = (NSIndexPath *)sender;
PFUser *user = [self.friends objectAtIndex:indexPath.row];

 ProfileViewController *pViewController = (ProfileViewController *)segue.destinationViewController;
        pViewController.selectedUser = user;

}

in the ProfileViewController you can access the selectedUser's details by doing something like this NSString *nameString = [self.selectedUser objectForKey:@"name"];

hope that helps

Rutger Farry
Rutger Farry
10,722 Points

Implement the delegate method tableView:didSelectRowAtIndexPath: in the FriendsViewController. Assuming you created a segue with identifier "showProfile", your code might look something like this:

- (void)tableView:(UITableView *)tableView 
didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
        [self performSegueWithIdentifier:@"showProfile" sender:self];
}

Then in your ProfileViewController.m, you will need to make sure it knows which profile to load in the viewDidLoad method