The following method won't get called when I scroll the tableView far enough so that it scrolls out of bounds.
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section
Why could this be happening?
Make sure that any UITextFields or UITextViews are not displaying their keyboards.
You can call:
[textView resignFirstResponder];
If any textField or textView is the firstResponder of the responder chain, the UITableView will not call the didEndDisplayingFooterView: method
Related
I have a UITextField in one of my collection view cells. I want it to become first responder as soon as that cell is on screen.
So, I call [cell.textField becomeFirstResponder] in cellForItemAtIndexPath. However, this only works when the app is opened (the cell containing the uitextfield is already visible on app launch), if I scroll away from the cell and than scroll back to it, the textfield does not become first responder anymore.
What could be the problem?
EDIT: I am programatically scrolling the collection view to the cell containing the UITextField before calling becomeFirstResponder
It seems as the scrolling of the collection view made the collection view the first responder until the scrolling finished, so I made my textfield the first responder in this delegate method:
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
You should put the code in the
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
function as according to the class ref:
Tells the delegate that the specified cell is about to be displayed in the collection view.
I have tableview in UIViewController & I have added text filed in prototype cell. I can't be able to scroll the table view when I am dragging the text filed area in the table view. When I am hiding the text field or making user interaction disable of the text filed on that time I am able to scroll the tableview.
Any resolution will be appreciated.
Thanks.
If the text field has userInteractionEnabled set to YES, and it fills the entire cell, you can not get the cell to listen to touch. In order to get the cell to respond to touches, you need to set the userInteractionEnabled of the text field to NO.
And if you want to make the text field editable, when the cell is selected, add the following code in didSelectRowAtIndexPath: method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the reference to the text field
[textField setUserInteractionEnabled:YES];
[textField becomeFirstResponder];
}
or
you have not make textField so large that it covers whole cell
Hope this will help :)
I have a non scrollable UITableView inside an UIScrollView. And I'm having the problem that when I touch a row, the callback didSelectRowAtIndexPath: is not being called on the first tap, but after the first tap everithing works.
A few considerations:
After the first tap, the table view works normally, every tap works in every cell.
This happens just after I scroll the UIScrollView. If I don't scroll the UIScrollView, this never happens.
I have overriden the UIScrollView's touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view and the event does pass throw here, the view is a UITableViewCellContentView effectively.
I just don't know why the event is not been sent to the UITableView on the first time, and on the following ones it does.
If you have UIScrollView that contains vertical content and UITableView as part of this content, you must at least disable scrolling on UITableView - otherwise it's confusing for the user when he will scroll your mainView and when tableView, and also confusing for the framework because it's not clear where to send panning gestures.
As a rule of thumb - you should avoid putting table views inside scrollViews, unless you really know what you're doing.
Please disable scrolling of your table view and check the datasource and delegate are connected to your table view. If not follow the bellow code
#interface myClass ()<UITableViewDataSource, UITableViewDelegate>
- (void)viewDidLoad {
[super viewDidLoad];
self.myTableView.scrollEnabled = NO;
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
}
I have a UITextField at the top of my Table View, after the text field is selected I want the keyboard to disappear. I know to call [[self view] endEditing:YES]; but I don't know how to check for the scroll. A good example of this is IMessage, when the keyboard is in view you can scroll up to collapse it, I want my table view to work inversely.
UITableView is a subclass of UIScrollView. By being the table delegate (implementing <UITableViewDelegate>) you are also the scroll view delegate (<UIScrollViewDelegate>) and as such you can implement:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Then you will receive a notification whenever the table view is scrolled. You can then also use scrollView.contentOffset to check where the table has scrolled to (which direction it's scrolling in).
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[textField resignFirstResponder];
}
Try other method in UIScrollViewDelegate if you need other behaviour.
Call resignFirstResponder where appropriate.
It seems you use UITextField in your cells. Use UITextFieldDelegate protocol to know when UITextField ends being edited:
-(void)textFieldDidEndEditing:(UITextField*)textField
{
[textField resignFirstResponder];
}
This is what I'm trying to achieve:
I want a UITextField that is in UITableViewCell to become first responder only when the cell touched. I would like the text field to become the first responder only when I set it to first responder in the method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath`
Any idea how I can achieve this? When the textfield is touched directly, tableView:didSelectRowAtIndexPath: is never called.
Thanks in advance.
I guess, u have a custom UITableViewCell. In that u could have a UITextField member. Right?
In the custom cell class, override the method,
- (void)setSelected:(BOOL)selected animated:(BOOL)animated:
In that , if selected == YES, then make the text field as first responder. Else , resign the first responder.
Let an object be the delegate of the UITextField and implement textFieldShouldBeginEditing:; return NO if the cell hasn't been selected. (You might be able to always return NO from this method, if calling becomeFirstResponder directly bypasses the check.)
For having the textField become the first responder when a uitableviewcell is selected, use your textField as your property, and call [self.textField1 becomeFirstResponder];
Note: You will need as many properties as your the number of UITableViewCells as each cell has a textField.
When a textField is touched, the compiler will not know that the corresponding row got selected.
For this you will need to use tags, such as textField.tag == 0 for the first textField, textField.tag ==1 for the second TextField and so on. And in the textFieldDidBeginEditing you should check for the tag, and then link that value with the corresponding row selected.
Did any of these make sense ? :)
First, you need a custom table cell, your own subclass of UITableViewCell. In that implementation, you need to implement hitTest: to determine where the touch occurred. In that method you can determine if the touch was in fact inside the rect of your UITextField, and if it was, make it the first responder. Here's an example from some code I wrote for a project:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (self.editing) {
if ([nickname pointInside:[self convertPoint:point toView:nickname] withEvent:nil])
return [nickname hitTest:[self convertPoint:point toView:nickname] withEvent:event];
return [super hitTest:point withEvent:event];
}
return [self contentView];
}
The attribute nickname, in this case, was a UITextField inside the custom UITableViewCell.
The condition around self.editing may or may not be relevant to your application. The idea here is show you how hitTest: might be used, in general.