UITextField in UITableViewCell - iphone

I have a standard UITableViewController. In the cellForRowAtIndexPath I add a subview to cell.contentView. This UIView itself contains a UITextField object. This object will not respond to touches. I have set the delegate to the UIView and implemented all the methods. I have also set userInteractionEnabled = YES. When I tap the UITextField nothing happens! I feel it's being absorbed by the cell. What would be the easiest, least messy fix?
Best,
Joris
EDIT: Sorry, see my answer. I solved it.

I'm an idiot. Sorry for wasting everyone's time. I hadn't properly said the UIView's frame. It of course did display the UI elements, but wouldn't respond to them.

Try just adding the textfield as a subview of the cell, this is what I have done in a couple of my apps and had no problems with it

In your tableView, try to set
allowsSelection = NO;

Try setting the editing property of the table view to YES.
Check this answer
Editing a UITextField inside a UITableViewCell fails

Related

Strange Behavior-Did select row touch not responding for UITableViewCell

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 :)
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.
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.
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.

Touch on UIButton in a UITableViewCell cannot scroll the table

I need to have a UIButton inside a UITableViewCell, everything works fine except when I touch inside the button and move my finger, the table does not scroll.
I tried to subclass UIButton and in touchesMoved: method send the same message to self.nextResponder, or call touchesCancelled and hope it will pass the touch event to next responder, they both do not work.
Is there any good way to solve this problem? Currently I am adding a UIView on top of the UITableViewCell, and detecting touch events manually, passing result to the button or the rest of the cell respectively, but this is a little bit dirty.
What you can try is setting the delaysContentTouches property of the UITableView to YES.
Additionally you can set the canCancelContentTouches to YES.
If the value of this property is NO, the scroll view does not scroll
regardless of finger movement once the content view starts tracking.
Source: UIScrollView Class Reference
Try:
_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;
The best way is to make a custom cell and do your work neatly.
Check the Apple docs

UITextView in custom UITableViewCell not responding to didSelectRowAtIndexPath

I have a UITextView in my custom UITableViewCell and the issue is that when I tap on it it won't respond to the didSelectRowAtIndexPath or even swipe events. How can I fix this? This UITextView is not editable. The reason why I use this over a UITextField is because I want to be able to detect links easily.
I realize this is an old question, but I recently had the same issue. The fix in my case was to simply turn off "User Interaction Enabled" for the UITextView.
you need to forward the touch messages from UITableView to UITextView
UITextView inside UITableView
The first idea that came to mind...
In cellForRow set the textfield tag as the indexpath.row
Implement - (void)textViewDidBeginEditing:(UITextView *)textView
Based on this textView.tag, call the selectrow
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:textView.tag inSection:<#(NSUInteger)#>]
animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>]
I don't know if it's what are you looking for But in my case i had a custom cell with UIImage, and UITextView and only when I clicked on UIImageView i got didSelectRowAtIndexPath recogniser. Make sure UITextView is user interections unable like that to fix the problem
Check if your TableView Selection property is set to NO
Wrong :
tableView.allowsSelection = false
DidSelect Wont be called
It has to be:
tableView.allowsSelection = true
Also Check your Nib

iphone programming ?. Change UITableViewCellEditingStyle image?

I just need to know is it possible to change UITableViewCellEditingStyle image ?. If possible please tell me How to do that?
I don't see any delegate methods for changing the editing-style view.
You could change the editing button title with the delegate method -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:, however.
You could also override UITableViewCell and create a custom cell with UITableViewCellEditingStyleNone and a custom editing style behavior and appearance.
In case you're still interested you can actually get this to work by intercepting willTransitionToState and didTransitionToState in a subclass of UITableViewCell. The solution does involve "hacking" around in the cell view hierarchy. Look for the description of recursiveDescription on UIView on how to "dump" a hierarchy, but you will find a UIImageView of which you can change the .image property...
Fairly ugly hack, but does not actually use any private api.

Touch events aren't reaching touches methods?

I have a View Controller, and a UIImageView as a subview. That UIImageView also has a subview of that same type.
I have:
self.userInteractionEnabled = YES;
set for each. My touchesEnded code was working. Any idea what would cause this? No touches are even reaching the touches events. I don't understand?
Any help appreciated.
Thanks // :)
Sounds like you've gone all the way up the chain and checked the self.userInteractionEnabled all the way up to the top, right? Ok, now check if any view has exclusiveTouch set to YES.
Also, if you called resignFirstResponder on the parent view, instead of a UIText field, you would relinquish events.
Lastly, beginIgnoringInteractionEvents, can cause this too.
I just found this solution from saimhann2002 who was having a similar problem.
Thanks for the reply. I have been able to fix the problem now. The issue was that I was adding the subview to the MKMapView rather than the view of the ViewController. I don't know why this is an issue. If you do I would be interested to hear. Adding the view as a subview to the view of the ViewController fixed everything, with the view now accepting the touches, even when its colour is UIColor clearColor.
That works!