表视图didSelectRowAtIndexPath,仅在选择第二次点击后生效 [英] 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.
例如,我有头盔,棍子和手套。如果我按头盔,什么也没发生。然后,如果我按Stick,它会为头盔而不是棍子做didSelectRowAtIndexPath。
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];
}
}
推荐答案
这是因为您实现了 didDeselectRowAtIndexPath
,而不是
didSelectRowAtIndexPath
。
That is because you implemented didDeselectRowAtIndexPath
instead of
didSelectRowAtIndexPath
.
这篇关于表视图didSelectRowAtIndexPath,仅在选择第二次点击后生效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!