reloadData in textFieldDidBeginEditing keyboard not appearing - ios

I have textfield in every row of tableview. click on textfield
-(void)textFieldDidBeginEditing:(UITextField *)textField
method called but keyboard not appear. I have written
[tableView reloadData];
in the method.
Keyboard appear if I remove [tableView reloadData]; this
any solution ?

Have you check the property KEYBOARD ? By selecting tableview and in attribute inspector set Keyboard property to do not dismiss and try

press cmd+K from keyboard if you are using simulator.

Related

How to raise a table cell above keyboard level with textfield inside that cell is focused?

I'm using the following to raise a textfield inside a table cell above keyboard level. But this only works if I tap the textfield. If I focus the text field programmatically ,i.e., [textField becomeFirestResponder], it doesn't work. Edit: also textFieldShouldBeginEditing: is being called but the code inside isn't performing as expected.
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
CGPoint pointInTable = [textField.superview convertPoint:textField.frame.origin toView:_tableView];
CGPoint contentOffset = _tableView.contentOffset;
contentOffset.y = (pointInTable.y - textField.inputAccessoryView.frame.size.height);
[_tableView setContentOffset:contentOffset animated:YES];
}
return YES;
}
Try calling the [self textFieldShouldBeginEditing:textField] after setting [textField becomeFirstResponder]
call [textField becomeFirstResponder] and implement your keyboard avoiding code in textFieldDidBeginEditing as it is called after editing has begun. On the other hand textFieldShouldBeginEditing is called before beginning editing. You can properly obtain the keyboard height after editing has begun.
You can use third party class TPKeyboardAvoidingTableView
Which will automatically adjust and scroll TableView when keyboard get opens.
https://github.com/michaeltyson/TPKeyboardAvoiding

Tapping between UITextFields in iOS7

When a UITextField is selected and has a keyboard shown, if I tap other parts of the view the keyboard disappears.
If I tap another UITextField, the keyboard stays up, the first textfield is deselected, and nothing happens. Then I need to tap on the other UITextFIeld again for selection to happen and a keyboard to appear.
Is there a way to make a second UITextField immediately accessible when a first UITextField is selected?
If you reload the tableview in textFieldDidEndEditing, you'll break selection in this way. Don't do that.
try it, press another view should call below fn.
-(void)disappearKey{
[self.view endEditing:YES];
}
after keyboard disappear, Tap any textfield, will appear keyboard.
First of all I think its a bug that the keyboard is not dismissed and opened again when tapping on another UITextField or UITextView. It should be reported and Apple should fix it.
Using the textfield delegate methods and registering for keyboard notification it should be possible to manually keep track if the user tapped on another textfield and the keyboard did not close and reopen. At the very least you should be able to detect when this is happening and close the keyboard manually by [textField resignFirstResponder];
The keyboard notification are as follows:
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
I'm''pretty sure you know the UITextfield and textview delegate methods
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
I am not in an active project at the moment so I'm not sure if I just ignored the problem but I can't recall this happening to me.
you can use BSKeyboardControls. just see the demo and decide to
use or not.
or you can do you have to set tag in sequence to the each textfield
in uiview. then use the below code.
-(BOOL)textFieldShouldReturn:(UITextField*)textField
{
NSInteger nextTag = textField.tag + 1;
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
[nextResponder becomeFirstResponder];
} else {
[textField resignFirstResponder];
}
return NO;
}

iOS - Shifting from UITextField to another doesn't start the Second One

Here is the UI:
I have a table view that has rows including text fields. For example row1 has textField1 and row2 has textField2.
Now, if the user taps the textField1, everything works fine. The delegate is called and everything.
If the user, then, taps the textField2, only the textFieldDidEndEditing: is called for textField1. textFieldDidBeginEditing: is not called for textField2 (I am pretty sure that textField2 delegate is set, because when I then tap textField2 (again), it starts editing (textFieldDidBeginEditing: is now called)
You may think this is not a real problem. The problem is that the iOS keeps showing the keyboard! With no text fields associated to it! I even loop to all text fields in all visible rows and resign them with no luck.
Seems a bug in iOS, right?
Edit: Here is the code in the delegate
- (void) textFieldDidBeginEditing:(UITextField *)textField {
[self fixTableViewOffsets];
RSMCellEditPricesCell *cell = (RSMCellEditPricesCell *) [[textField superview] superview];
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell]
atScrollPosition:UITableViewScrollPositionTop
animated:YES];
}
- (void) textFieldDidEndEditing:(UITextField *)textField {
self.currentPriceTextField = nil;
[self fixTableViewOffsets];
[self.tableView reloadData];
}
First of all, be careful with the naming conventions, if you are adding a label at the end of a variable that variable should be a UILabel not a UITextField. Second your problem might be in the textFieldDidEndEditing method, you are calling resignFirstResponder on all your text fields(if the cell.priceLabel is a text field). You shouldn't callresignFirstResponder in textFieldDidEndEditing or textFieldSouldReturn because if those methods are called the text fields are already resign as first responder.
I couldn't find a fix for it. However, as a workaround, I disabled the second text field. When the user taps this field, it will trigger the touch event on cell, not the text field which will dismiss the keyboard. Then, I enable all text fields and the user can select this second text field again.
It's not quite a solution and it doesn't provide the best UX. Still, it work.

UItableview and Keyboard with previous and next button scrolling issue - iPhone

Here I have a tableView on a scrollView. Each row contains a textField. Next button is ok(view animating properly on upword) but when I press on previous button on keyboard, I have to show down the view one by one according to the textField. How can I solve this? I have to do it in many views. Please help me as soon as possible. I badly need it. May be I'm doing wrong somewhere. Sorry for my language problem. Sample code may be helpful.
Hi Please try the below method to scroll your tableview up and down based on which text field is selected, write this code in textfield delegate method
- (void)textFieldDidEndEditing:(UITextField *)textField{
// calculate the nsindexpath based on the textfield which is selected
//- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated;
[yourtableview scrollToRowAtIndexPath:calcutaedIndexPath atScrollPosition:UIScrollViewPositionTop animated:YES];
}
Hope it will help you

Remove keyboard when table cell selected

I have a modal set up like this:
Despite appearances, the first two fields are UITextFields that become first responders and display the keyboard. The third 'Department' item is a table view and pushes another view.
I have implemented a scroll view so that while either of the fields is being edited, the user can scroll around and reach the department cell:
When it is selected, before the push, I would like to hide the keyboard. It's a small detail, but try adding a new event on Apple's 'Calendar' app. It opens with the first text field as first responder (so keyboard is present). If you select the start/end cell, the keyboard hides as the next view is pushed.
How do I achieve this? As a test I tried:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"hiding keyboard");
if ([ingredientName isFirstResponder]) {
NSLog(#"resigning name field");
[ingredientName resignFirstResponder];
}
else if ([ingredientAmount isFirstResponder]){
NSLog(#"resigning amount field");
[ingredientAmount resignFirstResponder];
}
}
The logging confirms that these are getting called. But the keyboard does not hide. It simply stays in place as the view slides out. And on return, the previous field still has focus (and the keyboard is out).
Any ideas?
resignFrstResponder will not dismiss the keyboard when you're using a modal view.
Another dev found a workaround for this behavior here: http://viraj-workstuff.blogspot.com/2010/12/resignfirstresponder-does-not-hide.html
Not terribly elegant, but try stealing the firstresponder status with an ad-hoc, invisible UITextField:
-(void)dismissKeyboard {
UITextField *textField;
textField=[[UITextField alloc] initWithFrame:CGRectZero];
[self.view addSubview:textField];
[textField becomeFirstResponder];
[textField resignFirstResponder];
[textField removeFromSuperview];
// [textField release] // uncomment if not using ARC
}
Two things:
Are you using a segue for pushing that other VC? If so, resign the keyboard in the prepareForSegue method.
If not, try using willSelectRowForIndexPath instead of didSelectRowAtIndexPath

Resources