Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view didSelectRowAtIndexPath, only works after selecting second click

I have a table view which I've configured so that when the user taps the row, it will move to a new view based on the name of the particular cell. However, when I first click a cell it does nothing, and when I click the next cell, it will act as if I had clicked the first cell.

For example, I have Helmet, Stick and Gloves. If I press Helmet, nothing happens. Then, if I press Stick, it will do the didSelectRowAtIndexPath for the Helmet and not the Stick. Any suggestion as to why this is happening?

//Tapping to change on row
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"%@", cell.textLabel.text);
    if([cell.textLabel.text isEqualToString:@"Helmet"])
    {
        [self performSegueWithIdentifier:@"toHelmetView" sender:indexPath];
    }
}


//Segue control, fetch helmet and send it
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"toHelmetView"])
    {
        // Fetch the selected object
        //EquipmentCategory *o = [_frc objectAtIndexPath:[self.tableView indexPathForSelectedRow]];

        // Configure the next view + controller
        HelmetView *nextVC = (HelmetView *)segue.destinationViewController;

        nextVC.title = @"Helmet";
        nextVC.model = self.model;
        nextVC.h = [self.model helmetForPlayer:self.p];
    }

}
like image 940
Jordan Avatar asked Apr 09 '14 19:04

Jordan


1 Answers

That is because you implemented didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath.

like image 116
Martin R Avatar answered Oct 17 '22 00:10

Martin R