在UITableView上触摸事件? [英] Touch events on UITableView?
问题描述
我有 UIViewController
和 UITableView
作为视图中的子项,
我想要做的是当我触摸任何一行时,我在底部显示一个视图。我希望隐藏该视图,如果用户触摸任何其他地方,然后触摸行或bottomView。
I have UIViewController
and UITableView
as child in the view,
what I want to do is when I touch any row I am displaying a view at bottom. I want to hide that view if the user touch any where else then rows or the bottomView.
问题是当我点击 UITableView
它不会触发 touchesEnded
事件。
The problem is when I click on UITableView
it doesn't fires touchesEnded
event.
现在我怎样才能检测 UITableView
并将其与行选择事件区分开来。
Now how can I detect touch on UITableView
and distinguish it with row selection event.
谢谢。
推荐答案
我很长时间以来一直面临着这个问题而且没有任何可行的解决方案。最后我选择了替代方案。我在技术上知道这不是解决方案,但这可能有助于某些人确实寻找相同的东西。
I was facing the problem since a long time and didn't got any working solution. Finally I choose to go with a alternative. I know technically this is not the solution but this may help someone looking for the same for sure.
在我的情况下,我想选择一行后会显示一些选项我触摸桌面上的任何地方或查看我想要隐藏这些选项或执行任何任务,除了之前选择的行,我执行了以下操作:
In my case I want to select a row that will show some option after that I touch anywhere on table or View I want to hide those options or do any task except the row selected previously for that I did following:
-
设置视图的触摸事件。当您触摸视图中除表视图之外的任何位置时,这将执行任务。
Set touch events for the view. This will do the task when you touch anywhere on the view except the table view.
TableView的didSelectRowAtIndexPath执行以下操作
TableView's didSelectRowAtIndexPath do following
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
if(indexPath.row != previousSelectedRow && previousSelectedRow != -1) {
// hide options or whatever you want to do
previousSelectedRow = -1;
}
else {
// show your options or other things
previousSelectedRow = indexPath.row;
}
}
我知道这是较老的帖子而不是一个好的技术解决方案,但这对我有用。我发布这个答案是因为这可能对某人有帮助。
I know that this is older post and not a good technical solution but this worked for me. I am posting this answer because this may help someone for sure.
注意:这里写的代码可能有拼写错误,因为这里直接输入。 :)
Note: The code written here may have spell mistakes because directly typed here. :)
这篇关于在UITableView上触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!