Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

ios - 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];
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That is because you implemented didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...