ios - didSelectRowAtIndexPath 不会在 ViewController 中触发

标签 ios uitableview didselectrowatindexpath

所以,我添加了一个 UITableViewControllerUITableViewCell变成 UIViewControllercellForRowAtIndexPath委托(delegate)方法有效,didSelectRowAtIndexPath才不是。有没有人有任何想法?

  • 编辑 2:UITableView 的代表设置为 UIViewController .
  • 编辑 3:我在另一个 Stack 问题 here 上找到了我的问题的答案.基本上我有一个 UITap...在我的 [self view]阻止了didSelectRow... .我不知道为什么点击会阻止委托(delegate)方法,我也不知道如何让点击和表格同时工作。
  • 编辑:让我烦恼的部分是我已经在早期的应用程序上得到了这个精确的设置。所以这意味着我在路上的某个地方错过了一步。问题是,我已经梳理了所有步骤,并将以前的应用程序与当前应用程序进行了比较,我真的不知道我错过了什么。

  • 我已将日志记录添加到两种委托(delegate)方法中,而一个输出,另一个没有。

    View Controller .h
    #import "...TableViewCell.h"
    ...
        UITableViewDataSource,
        UITableViewDelegate
    ...
    

    View Controller .m
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"cellForRowAtIndexPath");
        ...
        return Cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"didSelectRowAtIndexPath");
    }
    

    ...TableViewCell.h(内容不重要)

    ...TableViewCell.m(内容不重要)

    最佳答案

    我在 another StackOverflow question 上找到了答案.

    我有一个 UITapGestureRecognizer添加到 [self view]我注释掉了,然后委托(delegate)方法起作用了。

    谁能告诉我为什么这有效,以及如何获得 UITapGestureRecognizer在与 UITableView 相同的屏幕上工作?

    // Hide keyboard when user taps outside of it
    UITapGestureRecognizer *tapGestureRecognizer =
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(hideKeyboardOnTap)];
    //[[self view] addGestureRecognizer:tapGestureRecognizer];
    
  • 编辑:更正 UITapeGestureRecognizer 的错字至UITapGestureRecognizer
  • 关于ios - didSelectRowAtIndexPath 不会在 ViewController 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19084849/

    相关文章:

    ios - session 重启后 AVcapture session 启动缓慢

    iphone - 跟踪 UITableViewCells

    json - 如何将 TableView 中的选定行(JSON)发送到另一个 View Controller ?

    ios - 编辑时tableView中没有didSelectRowAtIndexPath()

    ios - 具有多个 NSMutablearray 的树 TableView

    ios - Mapbox-iOS-SDK 6.3.0 pod 安装错误 403 Forbidden

    ios - 使用两种不同的字体动态设置 Storyboard生成的 UILabel 的属性字符串(Swift)

    ios - 从一种模态 VC 到另一种模态 VC 的快速过渡

    iOS 将 ScrollView 添加到现有 View

    ios - 最佳实践 : Using Size Classes for Single table view to dual table view