Strange Behavior-Did select row touch not responding for UITableViewCell

你。 提交于 2020-01-14 14:38:27

问题


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

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!

Thanks all in advance :)


回答1:


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:

In the view that you implemented UITextFieldDelegate

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

Declare a UITapGestureRecognizer as a property:

@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:)];

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

[self.superview.superview addGestureRecognizer:gestureRecognizer];

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

[self.superview.superview removeGestureRecognizer:gestureRecognizer];

This will totally solve the problem.




回答2:


Did you use a UITapGestureRecognizer on your tableView? I had the exactly same problem as you did today, and then I figured out that it was the gesture recognizer that blurs my intention for selecting a row by tapping. When I removed it, the tableView was back to normal.

Hope this helps.




回答3:


I had this same problem and solved it by ticking "Scrolling Enabled" in the table view attributes.

My table view doesn't need scrolling, so it doesn't affect the app in any other way, except now I don't get the first unresponsive tap after a swipe gesture.



来源:https://stackoverflow.com/questions/9939509/strange-behavior-did-select-row-touch-not-responding-for-uitableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!