IPhone - textField in the table ViewCell - scrolling the screen clears the value

I have a textField inside a tableViewCell. I recently noticed that if I enter a value in a text box and then scroll the cell from the screen, the value in the text box will disappear.

I have a defense against this. If there is no current UIKeyboard, the tableView cannot scroll far enough to redraw the cell. However, some users do not use the key made on the keyboard to force the keyboard to leave, but instead scroll up to break the program.

Is there a way to immediately save the textField string for a variable or save the scroll of the View table or make the keyboard disappear if the user tries to scroll the View table?

I don’t have a NIB file for this view, it is a software tableViewController, so I can’t do anything in Interface Builder with invisible custom buttons, as suggested in other StackOverflow questions.

+6
iphone uitextfield uitableview
source share
3 answers

Are you creating a text field inside the cellForRowAtIndexPath :: method? If so, it can be re-created each time the cell scrolls.

You must save the link to the text field on your controller and reuse it in cellForRowAtIndexPath ::

+5
source share

The answer to this question is to implement the ScrollView delegation method. UITableView inherits from UIScrollView.

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; [textField resignFirstResponder]; } 

This rejects the keyboard as soon as the tableView starts scrolling.

Through this inheritance, you can also hold the tableView from scrolling, period. Set the scrollEnabled property to NO, a la

 self.tableView.scrollEnabled = NO; 
0
source share

You must set the delegate from the NSTextField that you created for the controller, and then implement textField:shouldChangeCharactersInRange:replacementString: in your controller so that you receive a notification at any time when the text changes in the text field.

When the text changes the saving of the changed text in the property of your controller.

When you create an NSTextField in cellForRowAtIndexPath , set the value from this property.

Remember that with Cocoa, you need to save the model data separately from your view.

0
source share

All Articles