textfield cursor missing and keyboard scroll problem when select textfield from textfield

I have a UITableView with UITextField. When I edit and exit those textField one by one, everything is fine (cursor, keyboard, scroll to unhide field from keyboard etc). But if I select another textField while editing one, I got no cursor and keyboard scroll simply not there... but I can edit text normally.. its like it s half activated... I tried to force resign but no results! What do you think? Thanks!


Ps: I declared all delegate for tableview and textfield

I have a UITableView with UITextField.


Where are the UITextField ? Inside each cell ?

Independant from the tableView ?


When I edit and exit those textField one by one

What do you mean one by one ? Do you mean you hit return after editing the textField ?


But if I select another textField while editing one,

So that happens if you have not hit return ?


What sentEvents have you connected the TextField to ?

You have to connect the IBAction to:

Did end on exit : that handles when you hit return

Editing Did End : that handles when you select another textField (the initial is no more first responder)

Hi!

thanks for reply!

Its uitextField inside each cell of the uitableview. When I edit and tap return or tap anywhere (I use single tap gesture to dissmiss keyboard) everything is fine ( the scroll work to prevent keyboard from hiding the textfield and the cursor is there).

But if I edit a textField and select another one to edit it without escaping the actual one , the keyboard hide and show but hide the textfield and there is no cursor , but I can enter text!


I tried to force resign, even to wait few second in background and then use becomeFirstResponder to activate the textField but I must exit by taping return key or tap somewhere to exit the field and then select the other field...


I hope it s better explained!


My Textfield and tableview are created programmatically and are declared as delegate... this problem is the only one so far.. each code works fine... I even try to call the method that rebuilt the table before to set focus on the textfield but still no cursor and keyboard still hide it..It s like it always keep a link with the first edited textfield or half activated or something...


thanks for your help its appreciated!

You did not answer all the questions, notably the last:

What sentEvents have you connected the TextField to ?

You have to connect the IBAction to:

Did end on exit : that handles when you hit return

Editing Did End : that handles when you select another textField (the initial is no more first responder)


If you create textFields in code, show the code to check if you have defined the right sent events notifications.

Did you implement the delegate func:

func textFieldDidEndEditing(UITextField)

Tells the delegate that editing stopped for the specified text field.


May have a look here as well:

https://stackoverflow.com/questions/28592374/differences-between-editingdidend-and-editingdidendonexit

Here what I have:

- (IBAction)textFieldFinished:(id)sender {      [sender resignFirstResponder];  }  

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
  [self.view endEditing:YES]; } 

- (void)textFieldDidEndEditing:(UITextField *)textField { //save value to userdefaults
 }

All those method works fine! Its only when selecting another textfield directly that I have no cursor and keyboard can

hide the field but I can enter some text and it saved correctly to userdefaults... The code to create the field is complexe

and depend on other method... but working fine! Here the main line that I think is the interesting one!


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:cellIdentifier];
 NSMutableDictionary* prefs = [NSMutableDictionary dictionaryWithDictionary: 
[[NSUserDefaults standardUserDefaults]persistentDomainForName:@"com.patpower.smscontrolprefs"]]; 
NSString *value =@"";  
   if(cell == nil) {       
  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
 [cell addSubview:tf];
 tf.delegate = self;           
   [tf addTarget:self   
action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];


Thanks again !

Arghh !


Please format the code in a readable way.

And use the formatter tool (<>)

Sorry about it!

I updated my awnser!


tf is the textfield..

I notice that if I make the screen rotate, the cursor gone and keyboard come to hide the field but I can write text... I will lock the portrait orientation but I still not understand why switching from textField is so messy! Thanks!

That's really partial code, but I do not see how you implemented the delegate func: textFieldDidEndEditing

Here what I have:

[cell addSubview:tf]; 
tf.delegate = self; 
[tf addTarget:self   action:@selector(textFieldDidEndEditing:)forControlEvents:UIControlEventEditingChanged];
 [tf addTarget:self action:@selector(textFieldFinished:) forControlEvents:UIControlEventEditingDidEndOnExit];

If not how should I implement it? Thanks

Everything is fine now, that was because I was rebuilting the table on didendediting... But I still have a problem ! I scroll the view when keyboard appear to not hiding the field... But sometimes I need to scroll a little more on certain fields.. So in the shouldBeginEditing, I set a cheat with the height of the field and add this cheat to keyboard height , the cheat is 0 if not applyable... It works fine but only one time! The cheat value stay the same, its like the method is only called once. I need to dissmiss keyboard and edit new textfield ... if I change textfield during editing it ll keep the old value... Any clue on that one? Thanks!

Hi,
Thanks for the reply! I think I should explain the problem again, I just cant find any awnser anywhere! :)
Code Block
I have a UITableView with UITextField in each cells. The cells are not the same height, I have a small one dedicated to the name and a large one dedicated to the phone number... So, small-large small-large small-large and so on...

I wish that if I select the small one to enter a name, the scroll action will unhide both small and large cell from the keyboard to be able to directly select the large one to enter the number...

If I select the large one, I want the scroll to only unhide this large cell from keyboard (the small one is before so visible).

The way I use is to store a value corresponding to the height of the large cell if I select a small one and 0 if I select a large one.

This value is updated fine, the only issue is that the delegate seems to keep only the first value active, so if the value changed, it wont scroll with this new value but with the old one...

So, if I hit return to dissmiss keyboard and select another textfield, everything is fine!

If I tap anywhere on the screen to dismiss keybord and then select a textfield, its fine too!

But if I select directly another textfield without escaping the active one to dissmiss the keyboard, it keeps the old value and not scroll correctly (exept if I select the same textfield size obviously).

IBAction , single tap etc are ok, all works exept for the part I described! When I select another textfield directly, the old one is deactivated and the new one activated correctly...

Here the code for the keyboard scroll:

Code Block
-(void)keyboardWasShown: (NSNotification*)aNotification
{
[UIView animateWithDuration:.3
animations:^(void)
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue].size;
self.kbheight = kbSize.height;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0,0.0,(kbSize.height+self.cheatheight),0.0);
self.table.contentInset = contentInsets;
self.table.scrollIndicatorInsets = contentInsets;
}];
}


In the keyboardDidHide I just reset. It s like the keyboard dont dissmiss when I go from one textField to another directly, even if the field get deactivated...

Thanks!
textfield cursor missing and keyboard scroll problem when select textfield from textfield
 
 
Q