To clean up my user interface, I want to use a table view to group a set of UITextField instances. I know I'm fudging the functionality of table view (I don't have a list of data I'm managing, just a set of user-entered data), but table view provides me with the layout & group I'm looking for (and simply text fields don't).
Essentially, I'm adding the text field as a sub view on a table cell. Then when the user tabs into the text field, they'll be able to enter data from the keyboard.
Since the text field is a sub view in a table cell, do I have to add any special selection functionality on the cell, or will a tap into the text field automatically engage the keyboard?
You're not fudging functionality, Apple does this in many of the delivered applications, and there is a sample project called Editable Detail View or something like that that shows how to do it.
Tapping the field will bring up the keyboard, but the keyboard won't dismiss unless you do something. In this situation, I usually use a keyboard with a return key, and have it take them to the next method. I do this by binding the Did End on Exit event of the text field to an action method. Figuring out how to go to the next row is a little bit gnarley, this is one way to do it:
One thing to keep in mind is that if a row scrolls off the screen, the cell will go into the re-use pool, so if there's a chance our table will scroll, make sure you register as the text field's delegate and keep track of the changes so that if the field rolls off and gets re-used, you haven't lost the value it held.
>> Tapping the field will bring up the keyboard, but the keyboard won't dismiss
>> unless you do something. In this situation, I usually use a keyboard with
>> a return key, and have it take them to the next method. I do this by binding
>> the Did End on Exit event of the text field to an action method.
This is going to be a very stupid question, but how do I do this binding programmatically? Because UITextField is a subview of the cell, I haven't figured out a way to get this set up in IB.
>> Tapping the field will bring up the keyboard, but the keyboard won't dismiss
>> unless you do something. In this situation, I usually use a keyboard with
>> a return key, and have it take them to the next method. I do this by binding
>> the Did End on Exit event of the text field to an action method.
This is going to be a very stupid question, but how do I do this binding programmatically? Because UITextField is a subview of the cell, I haven't figured out a way to get this set up in IB.
-M
You can drag the UITextField into the NIB file and create it that way!
I've created a subclass of UICell that has a UITextField as a property.
In the "cellForRowAtIndexPath" method in the view controller, I then set the delegate for the text field to the view controller.
In then have the view controller adopt the UITextFieldDelegate protocol and implement the method "(BOOL)textFieldShouldReturn" in the view controller. Within this method I update the model and resign firstResponder
When I enter data into the text field and hit "return", the model is updated and the keyboard goes away. <yeah!>