ios - 将 uitableview 添加到 uiview 后 didselectrowatindexpath not called ios

标签 ios objective-c uitableview didselectrowatindexpath

我创建了一个自定义 tableview displayCustomUnitTableView 和一个自定义 UIView displayView 并将 displayCustomUnitTableView 添加到 displayView。但我无法在 tableView 中选择任何行,即 didSelectRowAtIndexPath 未被调用。

我正在使用以下代码:

displayCustomUnitTableView = [[UITableView alloc]initWithFrame:CGRectMake(52.0, 110.0, 180.0, 110.0) style:UITableViewStylePlain];
displayCustomUnitTableView.delegate = self;
displayCustomUnitTableView.dataSource = self;
displayCustomUnitTableView.tag = 2;
displayCustomUnitTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
displayCustomUnitTableView.separatorColor = [UIColor blackColor];
displayCustomUnitTableView.rowHeight = 30.f;
[displayCustomUnitTableView setBackgroundColor:[ContentViewController colorFromHexString:@"#BCC9D1"]];
[displayCustomUnitTableView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
[displayCustomUnitTableView setAllowsSelection:YES];
[displayView addSubview:displayCustomUnitTableView];

cellForRowAtIndexPath:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"MyCell";
  UITableViewCell *cell= [tableView cellForRowAtIndexPath:indexPath];
  if (cell == nil)
  {
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier];
  }
  if(tableView.tag == 1)
  {   
    cell.textLabel.text = [storeUnitList objectAtIndex:indexPath.row];
  }
  else if(tableView.tag == 2)
  {
    cell.textLabel.text = [storeCustomUnitList objectAtIndex:indexPath.row];
  }
   return cell;
 }

didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 if(tableView.tag == 1)
 {
    unitString = [storeUnitList objectAtIndex:indexPath.row];
 }
 else if(tableView.tag == 2)
 {
    unitString = [storeCustomUnitList objectAtIndex:indexPath.row];
 }
}

提前致谢。

最佳答案

确保您在父 View 上没有任何 UIGestures。在那种情况下,UITableView 将不会得到触摸。

如果有,请使用:

- gestureRecognizer:shouldReceiveTouch: 委托(delegate)方法。

关于ios - 将 uitableview 添加到 uiview 后 didselectrowatindexpath not called ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31047397/

相关文章:

ios - 在导出到BigQuery的FirebaseAnalytics数据中,有些事件的ga_session_id为空

ios - 如果应用商店没有得到 30% 的提成,他们会批准应用程序吗?

ios - 在 tableview Objective-c 中对齐行中心的单元格

ios - 如何在不使用完成 block 的情况下在动画后执行代码?

Android NDK 与 iOS - 性能问题

iOS结合长按和滑动手势

ios - 作为 SubView VS ChildViewController 查看

当显示删除按钮时,iPhone UITableView 抑制公开按钮

iphone - 如何在 UITableViewCell 中创建具有圆形背景的数字(如电子邮件应用程序)?

iphone - Bundle ID 应该如何用于多个 Apple 应用程序?