【问题标题】:UITableView clicked and no cell selected,but long press trigger cell selectedUITableView单击并且没有选择单元格,但是选择了长按触发单元格
【发布时间】:2015-03-08 15:04:29
【问题描述】:

环境:Xcode 6.1.1;故事板 问题: 我正在创建一些列表,其中 UITableView 嵌入在 UIViewContrller instoryboard 中,并且所有单元格都无法通过单击选择,但可以通过长按意外选择。 我不知道为什么,我无法弄清楚。 我希望有人帮助我。 思考。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HBillCell *cell = [tableView dequeueReusableCellWithIdentifier:@"billCell"]; [cell loadInfo:self.dataSource[indexPath.row]]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"bill2detail" sender:nil]; }

【问题讨论】:

  • 您是否使用委托方法:didSelectRowAtIndexPath ?
  • 只要你不显示一点代码,没有人会帮助你......
  • @sasquatch 是的,我已经链接了dataSource委托和tableview委托,所有数据都可以正确显示,只有长按才能触发didSelecteRowAtIndexPath被调用。
  • @grzegorz-krukowski 代码很简单。只是:
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { HBillCell *cell = [tableView dequeueReusableCellWithIdentifier:@"billCell"]; [单元加载信息:self.dataSource[indexPath.row]];返回单元格; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"bill2detail" sender:nil]; } 
  • 不要将代码放在 cmets 中,它很难阅读。编辑您的问题以包含格式正确的代码。

标签: ios objective-c uitableview storyboard


【解决方案1】:

谢谢大家。这个问题是我自己在基类视图控制器的根视图上添加的点击手势造成的。

- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapBlankAction:)];
    tgr.delegate = self;
    [self.view addGestureRecognizer:tgr];
}

我想通了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多