【问题标题】:Table view didSelectRowAtIndexPath, only works after selecting second click表视图 didSelectRowAtIndexPath,仅在选择第二次单击后才有效
【发布时间】:2014-04-09 19:23:14
【问题描述】:

我有一个配置好的表格视图,当用户点击该行时,它将根据特定单元格的名称移动到一个新视图。但是,当我第一次单击一个单元格时,它什么也不做,而当我单击下一个单元格时,它就像我单击了第一个单元格一样。

例如,我有头盔、棍子和手套。如果我按下头盔,什么也不会发生。然后,如果我按下 Stick,它将为 Helmet 而不是 Stick 执行 didSelectRowAtIndexPath。关于为什么会发生这种情况的任何建议?

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

}

【问题讨论】:

    标签: ios objective-c cocoa-touch uitableview


    【解决方案1】:

    那是因为你实现了didDeselectRowAtIndexPath 而不是 didSelectRowAtIndexPath.

    【讨论】:

    • 我有同样的问题,但我有正确的 func didSelectRowAt..还有什么可能?
    • 我不知道人们怎么会犯 didDeselectRowAt 的简单错误,但我想通知这在模拟器中会发生,即使你已经用 didSelectRowAt 纠正了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2015-10-17
    相关资源
    最近更新 更多