【问题标题】:touchesEnded:withEvent: not being called from my UIView, which is on top of a UITableViewtouchesEnded:withEvent: 没有从我的 UIView 调用,它位于 UITableView 的顶部
【发布时间】:2010-12-23 11:41:05
【问题描述】:

我的标题中有一个 UITableView 和一个 UISearchBar。当用户在 UISearchBar 中单击时,我创建一个视图(bg:黑色,alpha .65)并将其放置在 UITableView 中的内容上。我想要的是当用户点击这个半透明的 UIView 时,从 UISearchBar 中退出第一响应者。我已经在我的 UIViewController(也是我的 UITableView 的控制器)中实现了touchesEnded:withEvent:,但是这个函数永远不会被调用。我这里有什么遗漏吗?

干杯,

罗伯

【问题讨论】:

    标签: iphone objective-c uitableview ios uiview


    【解决方案1】:

    您的控制器将只处理它自己的视图的事件,这可能是表视图。如果要在后面添加的视图中处理触摸事件,则需要继承 UIView 并实现touchesEnded:withEvent: 方法。

    【讨论】:

    • 感谢 murat,我使用此方法和 NSNotification 将触摸事件传递回我的主视图控制器。
    【解决方案2】:

    我找到了一个很好的链接,希望这个链接对你有帮助, 下载源代码以获得更多帮助

    用 UISearchBar 和 UITableView 构建一个 SearchView http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/

    【讨论】:

      【解决方案3】:

      你需要使用 UISearchBar 的 UISearchBarController,它具有你所寻找的内置功能。

      【讨论】:

        猜你喜欢
        • 2012-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多