奔跑的香蕉Go
2015-10-31 03:49
采纳率: 55.6%
浏览 2.0k

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];
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • TangYPcsdn2 2015-10-31 04:40
    已采纳

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

    已采纳该答案
    打赏 评论
  • 奔跑的香蕉Go 2015-10-31 04:01

    求大神解答0.0.00000

    打赏 评论
  • mifit 2015-10-31 04:37

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

    打赏 评论
  • zlq350026209 2015-11-02 23:31

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

    打赏 评论
  • Liu_Yes_sir 2015-11-03 06:05

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

    打赏 评论

相关推荐 更多相似问题