Reputation: 183
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.
Upvotes: 3
Views: 550
Reputation: 119031
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).
Upvotes: 3
Reputation: 445
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[textField resignFirstResponder];
}
Try other method in UIScrollViewDelegate
if you need other behaviour.
Upvotes: 2
Reputation: 1865
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];
}
Upvotes: 0