Hide keyboard when we scroll with TableView after we searched - iphone

I want to hide the keyboard when I scroll on TableView. That means, I search for an item and I see the results, when I scroll on the TableView the keyboard will hide or dismiss. Look at this image.

You need to track the action that runs when the tableView is being scrolled. UITableView is the subclass of UIScrollView. So, you can use all the methods from UIScrollViewDelegate for your table.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[textfield resignFirstResponder];
}
This will work.

Set up the scrollview delegate in your header then make it so when
- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollview{
[self.textfield resignFirstResponder];}
and when he stops scrolling
- (void)scrollViewDidEndDragging:(UIScrollView*)scrollview willDecelerate:YES{
//open keyboard back up}
edit:
my bad, i confused scrollview and tableview. disregard anything up there, i cant find anything for your problem

Related

UITableViewController won't scroll if keyboard appears

I have some TableViewController with static Cells and some TextFields. A few Days ago, everything works fine, the TableViewController managed the "scroll to cell if keyboard appear", the contentOffset, etc. and I don't had to use [self.tableView scrollToRowAtIndexPath:...] or something else.
But today I notice that the Table won't set the contentOffset and scroll. I don't know what or where I changed something to cause this behavior, I just added some Labels and change origins.
So, how is it possible to activate/deactivate the automatically scroll to cell, if the keyboard appear?
Or maybe the Storyboardfile is broken?
I found the Problem.
I added viewWillDisappear, but without [super viewWillDisappear:animated]; the TableViewController won't scroll, etc.

show subview when UITextField touched

I'm pretty new to iPhone development, so please excuse my ignorance. I've googled this a bit and so far come up with nothing useful. Here is what I would like to do:
I would like a subview to popup(with the rest of the screen showing in the background) when a UITextField is touched. The popup is a calculator UIView that I created in the IB. It seems it is better to have a popup show than a customized keyboard, due to Apple's developer guidelines.
Here is my question. How do I capture the touch on the UITextField and how do I show the subview?
I have tried things like below to show the subview, with no luck:
CustomCalculator *customCalc = [[CustomCalculator alloc] initWithNibName:#"CustomCalculator" bundle:nil];
UIViewController *calcController = [self.customCalc.view];
[self.view addSubview:calcController.view];
Use the delegate method:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//Add your subview here
return NO; //this will stop the keyboard from poping up
}
This way when someone taps the textfield, your view will popup instead of the keyboard.
Now once the user is interacting with your view, you will have to manipulate the string in the textfield.text property directly as a reaction to the User tapping buttons in your view.
Implement the UITextFieldDelegate and the method for it is
-(void) textFieldDidBeginEditing:(UITextField *)textField
The above method is fired when you touch the UITextField. You may then position the UIPopoverController (I'm guessing that is what you're using to show the view in a popup) and as soon as you're done there pass the values back to the UITextField. Hence the popover's/viewcontroller presented's delegate should be your textfield object.
EDIT: After seeing the other answer below it struck me that I forgot to tell you how to stop the keyboard from showing. Just make this the first line in the method I've mentioned above:
[textField resignFirstResponder];

Multiple UIText fields with Multiple UIPickerViews in UITableView

I have a grouped style UITableView with a HeaderView that is loaded from another .xib.
The HeaderView has 4 UITextFields in it:
2 of the fields should display the Keyboard and allow user input.
2 of the fields should display a UIPickerView and update the UITextField with selection.
The Main TableView (with the sections and rows) is filled with UITextFields as well.
The UITextField in the first section (indexpath.section = 0) displays a UIPickerView
All other UITextFields in the rest of the sections/rows should display the Keyboard
I can get the Keyboard to display correctly and dismiss when the Done button is touched for all the UITextFields that can display the keyboard.
I can get the UIPickerView to display correctly and dismiss (with Custom Save/Cancel buttons).
The problem I have is when mixing the two...
When I do the following I have a hybrid effect:
Step 1: Touch the first UITextField to begin to enter data with the Keybard.
Step 2: Enter some data in the UITextField.
Step 3: Touch a UITextField that displays a UIPickerView instead of the Keyboard.
The result is the Keyboard AND my custom UIPickerView being displayed at the same time with the Keyboard actually displaying ON TOP of my UIPicker!
Any suggestions on how to prevent this from happening?
Need to show some code, but most likely you're not calling [myTextField resignFirstResponder] just before calling the UIPickerView.
You need to resign your keyboard for your textField. From the fact that you did not do it, I am guessing that you did not resign the pickerView as well. So you need to resign both of them or they will continue to stay on the screen
Resigning the textField.
Implement UITextFieldDelegate
Implement
- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return 1;
}
Resigning pickerview:
Implement the picker view as your property and implement [self.yourpickerview resignFirstResponder] in textFieldDidEndEditing and in the IBAction of your custom DONE button for your picker view.

how to check if a view is behind the keyboard on iphone

in my application i have a bunch of textlabels and textviews. Sometimes the textview is underneath the keyboard. My question is if there's a way to check if a textview is behind the keyboard to move it up. I already know how to move views up, and i know about the keyboardWillAppear notifications, but i don't know how to check if the view is behind the keyboard. The thing is that i don't want to move the textview if it's not underneath the kayboard. How can achieve that?
Thanks in advance.
I would do the check for first responder as shown above
[text isFirstResponder];
then I'd check to see if the bounds of the text field's bounds are less than 215 (because i think that's the max height of the keyboard) and accommodate from there. so all together it looks like:
if([text isFirstResponder]){
if(text.bounds.y > 215){
text.bounds.y = CGPointMake(text.bounds.y-(text.bounds.y-215));
}
}
I think the only way to see this is to verify each UITextField and UITextView if it returns YES for
[_text isFirstResponder];
If any UITextField or UITextView is First Responder, than it means that the keyboard is on the bottom of the screen.
You can see the keyboard will appear by listening to UITextFieldDelegate and UITextViewDelegate ShouldBeginEditing events:
for UITextField it is:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;// return NO to disallow editing.
and for UITextView it is:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
Hope it helps.

Hide keyboard when touch uitableview

I have a custom cell with a uitextfield inside. I want to hide the keyboard when the user touch the screen, I put a custom uibutton over my tableView, and in the touch up inside event, I call
-(IBAction) hideKeyBoard
{
[customcell.textfield resignFirstResponder];
}
is it the right way to hide the keyboard with a uitableview because it don't works
No, a UIButton over your tableview is going to obstruct touches to the table, and views with alpha less than something like 0.1.
One method would be to subclass UITableView and override touchesBegan to detect a touch. From there, you have many options for how to deal with resigning first responder, notification, delegate method, reference to the text field.