UITableView 上的触摸事件? [英] Touch events on UITableView?

查看:17
本文介绍了UITableView 上的触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中有 UIViewControllerUITableView 作为孩子,我想要做的是当我触摸任何行时,我会在底部显示一个视图.如果用户触摸行或底部视图之外的任何其他位置,我想隐藏该视图.

I have UIViewControllerand 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:

  1. 为视图设置触摸事件.当您触摸视图上除表视图之外的任何位置时,这将完成任务.

  1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆