View Full Version : textfield in scrollable UITableView losing values
Aug 31, 2008, 10:48 PM
I have a UITableView with some custom UITableViewCell objects. The custom cell just wraps a textField object.
I have the table getting populated correctly, and all the text fields are showing up. The problem for me is that if I enter text in the text field and scroll it off the screen, when I come back to it the text is gone. Anyone have an idea why the text in the field is missing?
Sep 1, 2008, 01:18 AM
i figured out my problem, dumb mistake... I didn't realize that cells were aquired again every time they had to be drawn, and I was initializing the text to an empty string at that time.
That partly lead me to a different problem though. I read in the UITableView class refference that "UITableView caches table-view cells only for visible rows..."
Is there any way to change that behavior so that a table caches all cells? I have a full table full of text fields that can't all fit on the screen at the same time. When the user finishes entering text in all of these text fields, I want to iterate over all the cells in the table to grab the value in the text field and do some data processing with it.
With the table only cashing visible cells (and only being able to grab indexPaths to visible cells) i have no idea how I can do this... Again, if anyone has some insight, I would really appreciate it.
Sep 1, 2008, 02:46 AM
Wow~~~, you did a great job!
Actually, it was written in the guide of table view programming guide, but I still have some other similiar problem to refresh the data in each cell. Fine, I will try to find out why...
Sep 1, 2008, 06:40 AM
well, I was able to fix my problem but it involved a super ugly hack involving global variables and adding extra info to the custom cell to know what section it's in...
oh well, it works :p If anyone has a better solution for accessing all cells in a table including the ones that aren't visible, i'd still be very interested. I can't imagine i'm the only one who has ever wanted to iterate over a table that takes up more than the visible screen...
hope you get your problem worked out too supertoto!
Nov 24, 2008, 12:24 AM
A good thing to do is catch it via the delegate method textFieldShouldReturn. Then you can determine the indexPath of the item modified and then save it to a member variable in your class. Determining the indexPath from inside this method can be a little tricky :eek: - see this post for a good example of how to do it here (http://www.iphonedevsdk.com/forum/iphone-sdk-development/2116-uitextfield-subview-table-cell.html). Good luck!