奇怪的行为-选择行触摸对UITableViewCell没有响应 [英] Strange Behavior-Did select row touch not responding for UITableViewCell

查看:45
本文介绍了奇怪的行为-选择行触摸对UITableViewCell没有响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题,我不知道它是否对正常的细胞行为很尴尬,好像是这样!在问这个问题时,任何愚蠢的事情.通常,当我们触摸一个表格视图单元格时,发生的事情是它导航到一个视图控制器/一个已编码的控制器.现在奇怪的是它不响应选择或触摸.已经检查了是否在IB中选择了编辑时允许选择.我选择了它,现在的问题是当我触摸表格视图单元时它没有响应,而是当我水平滑动/长按时单元格正在导航,真的对这种奇怪的行为感到惊讶!我不明白为什么我需要滑动它才能在表格视图中进行单元格选择的原因.表格视图下方的按钮也正在发生这种情况!

I have a very strange problem,I don't know whether it is awkward to normal behavior of cells or not,it seems as if it is so!Hence I am giving it up to some one who can answer, apologize if any thing stupid in asking this question.Normally,when we touch a table view cell,what happens is it navigates to a view controller/a controller that is coded.Now what's strange here is it is not responding to selection,or touch.I have checked whether or not allows selection while editing is selected in IB or not.I have selected it,now the twist here is when I am touching a table view cell it is not responding,instead when I swipe it horizontally/when I long press the cell,it is navigating,really surprised at this strange behavior!I don't understand the reason why I need to swipe it to make selection of cell in table view work.This is also happening with button present below the table view!

我搜索了与我的案子类似的问题,但发现只有一个问题建议检查此方法,

I have searched for issues similar to my case,but I found just one question there it was suggested to check for this method,

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

但是我根本没有实现该方法,实际上我是一个带有几个项目的标签栏,在这里我有一个名为AddController的控制器,用于访问几个属性和字符串等.在控制器中声明,我是对其进行子类化,如下所示:

But i haven't implemented that method at all,what I have actually is a tab bar with several items,where I have a controller called AddController,for accessing several attributes and strings etc.. declared in the controller,I am subclassing it as follows:

@interface ViewController : AddController

现在,因为它是在我看到的问题中指定的,即我给的链​​接用来检查您是否在子类控制器页面中复制了相同的代码,我谈到了子类化以及我做了什么,希望每个人都理解!

Now because it was specified in the question I saw,i.e. the link I gave,to check whether u are copying the same code in subclass controller page,I spoke about subclassing and what I did,hope every one understands it!

任何人都可以指导我如何摆脱这个问题,并使表格视图单元格响应正常的触摸,任何帮助将不胜感激!

Can any one please guide me how to get out of this issue,and make table view cell respond to normal touches,any help is greatly appreciated!

首先感谢所有:)

推荐答案

进行了一些研究之后,我很确定这是tableView上的 UITapGestureRecognizer 引起了您的问题.如果您像我一样在单元格中具有文本字段,并使用 UITapGestureRecognizer 关闭键盘,这是我的解决方案:

After doing some research I'm pretty sure that it is the UITapGestureRecognizer on the tableView caused you the problem. If you were like me having the text field in the cell and using the UITapGestureRecognizer to close the keyboard, here's my solution:

在实现了 UITextFieldDelegate

(在我的情况下,我有一个名为TextFieldCell的自定义 UITableViewCell ),

(In my case I have a custom UITableViewCell called TextFieldCell),

UITapGestureRecognizer 声明为属性:

@interface TextFieldCell : UITableViewCell <UITextFieldDelegate>
{
    UITextField *theTextField;
    UITapGestureRecognizer *gestureRecognizer;
}
@property (nonatomic,retain) UITextField *theTextField;
@property (nonatomic,retain) UITapGestureRecognizer *gestureRecognizer; 

并在您的视图中对其进行初始化:

And initialize it in your view:

self.gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard:)];

-(void)textFieldDidBeginEditing:(UITextField *)textField 方法中,使用 superView 移至tableView并调用 addGestureRecognizer :

In the - (void)textFieldDidBeginEditing:(UITextField *)textField method, use superView to move up to your tableView and call addGestureRecognizer:

[self.superview.superview addGestureRecognizer:gestureRecognizer];

然后在-(void)textFieldDidEndEditing:(UITextField *)textField 中,只需删除手势识别器即可:

And in the - (void)textFieldDidEndEditing:(UITextField *)textField, just remove the gesture recognizer:

[self.superview.superview removeGestureRecognizer:gestureRecognizer];

这将完全解决问题.

这篇关于奇怪的行为-选择行触摸对UITableViewCell没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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