【问题标题】:didSelectRowAtIndexPath not called on Touch触摸时未调用 didSelectRowAtIndexPath
【发布时间】:2016-09-09 10:35:25
【问题描述】:

我的 didSelectRowAtIndexPath 方法没有被调用。我重新加载表并重新加载并调用 talbeView

的所有方法

这是我所有的tableview方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *s = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];

    NSString *cellIdentifire = @"CellRoomList";
    CellRoomList *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifire];
    if(cell == nil)
    {
        cell = (CellRoomList*)[[[NSBundle mainBundle] loadNibNamed:@"CellRoomList" owner:self options:nil] objectAtIndex:0];
    }

    cell.lblRoomName.text = s;

    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [app.Glb.arrayRoomList count];

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];
    NSLog(@"userName :---- %@",userName);
    ViewController *chatController = [[ViewController alloc] init];
    chatController.chatWithUser = userName;
    [self.navigationController pushViewController:chatController animated:YES];
}

我在堆栈中阅读了一些问题,但无法得到答案。

如果我长时间触摸单元格而不是单元格的颜色变化但不称为didSelectRowAtIndexPath

为什么不叫它?

这里是快照:

【问题讨论】:

  • 你有没有用你的viewController设置tableView委托tableView.delegate = self;
  • 是的,我在 XIB 上添加了它,这就是我调用其他方法的原因
  • 在 NSLog 中打印时是否可以检查用户名?
  • didSelectRowAtIndexPath 是 tableView 委托。 cellForRowAtIndexPath 和 numberOfRowsInSection tableview 数据源。所以你说两者都是连接的。与代表一起检查一次这个问题。删除一次再添加试试
  • 是的,它是一样的...@Vickyexpert

标签: ios objective-c uitableview tableview


【解决方案1】:

单元格中可能有其他视图可以拦截触摸事件。确保将 NO 设置为视图的属性 userInteractionEnabled

【讨论】:

  • 在您的自定义单元格中禁用视图(UILabel..)并检查表格行选择。
【解决方案2】:

我曾多次遇到这个普遍问题。

请注意以下事项

  1. 确保您的单元格对其内容没有任何类型的触摸/点击手势
  2. 确保您的视图没有应用任何触摸/点击手势
  3. 确保您没有任何应用了任何触摸/点击手势的视图或表格视图类别(扩展)[这一点更为关键,因为我们通常不希望这样做]
  4. 检查您是否有任何第三方负责触摸/点击手势

最常见的原因是视图中的手势阻止表格接触单元格。

【讨论】:

  • 是的,这就是问题所在,我正在添加手势以在查看点击时关闭键盘,这使得问题出现在这里。
【解决方案3】:

正如您所说,您正在获取用户名,这意味着您的方法正在调用但未重定向到另一个屏幕,因为您以错误的方式启动视图控制器,因此请通过以下方式更改它,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

   NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row];
   NSLog(@"userName :---- %@",userName);

   ViewController *chatController = [[ViewController alloc] initWithNibName:@"ViewControllerId" bundle:nil];

   chatController.chatWithUser = userName;
   [self.navigationController pushViewController:chatController animated:YES];
}

【讨论】:

  • 它调用了长按。
  • 它只会在点击时调用,因为我们在 didselect 方法中实现了逻辑,而不是像按下日志那样的手势,有时可能是第一次,但它应该只适用于触摸任何行
【解决方案4】:

检查选择是否设置为单选!

【讨论】:

    猜你喜欢
    • 2020-12-30
    • 1970-01-01
    • 2012-02-15
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    相关资源
    最近更新 更多