The didSelectRowAtIndexPath table view only works after selecting the second click

I have a table view that I set up so that when a user deletes a row, he will be moved to a new view based on the name of a particular cell. However, when I first click on a cell, it does nothing, and when I click on the next cell, it will act as if I clicked the first cell.

For example, I have a helmet, a stick and gloves. If I click Helmet, nothing happens. Then, if I press Stick, it will make didSelectRowAtIndexPath for the helmet, not the Stick. Any suggestion on 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]; } } 
+6
source share
1 answer

This is because you implemented didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath .

+32
source

All Articles