touchesEnded:withEvent: 没有从我的 UIView 中调用,它位于 UITableView 之上
我的标题中有一个 UITableView 和一个 UISearchBar 。当用户单击 UISearchBar 时,我创建一个视图(bg:黑色,alpha .65)并将其放置在 UITableView 中的内容上。我想要的是当用户单击这个半透明 UIView 时,从 UISearchBar 中退出第一响应者。我已经在我的 UIViewController (也是我的 UITableView 的控制器)中实现了 touchesEnded:withEvent:
但这个函数永远不会被调用。我在这里缺少什么吗?
干杯,
罗布
I have a UITableView and a UISearchBar in its header. When the user clicks in the UISearchBar I create a view (bg: black, alpha .65) and place it over the content in the UITableView. What I want is when the user clicks this semi transparent UIView is to resign the first responder from the UISearchBar. I have implemented touchesEnded:withEvent:
in my UIViewController (is also my UITableView's controller) but this function never get called. Is there something I'm missing here?
Cheers,
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的控制器将仅处理其自己的视图(可能是表视图)的事件。如果你想在后面添加的视图中处理触摸事件,你需要继承 UIView 并实现
touchesEnded:withEvent:
方法。Your controller will only handle events of its own view, which is probably the table view. If you want to handle touch events in the view you have added later, you need to subclass UIView and implement
touchesEnded:withEvent:
method.我找到了一个很好的链接,这个链接可以帮助你吗?
下载源代码以获得进一步帮助
使用 UISearchBar 和 UITableView 构建 SearchView
http://jduff.github。 com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/
i found a good link , may this link help you,
download the source code for further help
Building a SearchView with UISearchBar and UITableView
http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/
您需要使用 UISearchBarController 而不是 UISearchBar,它具有您要查找的内置功能。
You need to use UISearchBarController insted of UISearchBar,This having builtin functionality for what you looking for.