tableviewcell中的触发事件,为什么当我离开这一行才触发呢?

图片说明下面是我的代码

-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

//indexPath.row得到选中的行号。
NSLog(@"%ld",(long)indexPath.row);
switch (indexPath.row) {
    case 0:
    {   //初始化界面
        HLNoAudit *my = [[HLNoAudit alloc] init];
          my.title =[self.list objectAtIndex:0];
        //设置返回键
        UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
        back.frame = CGRectMake(0, 0, 30, 30);
        [back setBackgroundImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal  ];
        [back setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
        [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        my.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
        [self.navigationController pushViewController:my animated:YES];
    }
        break;
    case 1:
    {
        HLAlreadyAudit *my = [[HLAlreadyAudit alloc] init];
        my.title =[self.list objectAtIndex:1];
        //设置返回键
        UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
        back.frame = CGRectMake(0, 0, 30, 30);
        [back setBackgroundImage:[UIImage imageNamed:@"arrow_left"] forState:UIControlStateNormal  ];
        [back setTitleColor:[UIColor redColor]forState:UIControlStateNormal];
        [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        my.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
        [self.navigationController pushViewController:my animated:YES];

你选用的方法是错误的, 应该用didSelectRowAtIndexPath而不是 didDeselectRowAtIndexPath。使用didDeselectRowAtIndexPath方法第一次点击选中cell是没有反应的,当点击其他的cell之后才取消之前选中的cell,然后才能调用didSelectRowAtIndexPath方法。

求大神解答0.0.00000

[tableView deselectRowAtIndexPath:indexPath animated:YES];把它去掉吧

方法写错了 应该是 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

两个方法这有一个DE的差别,需要注意