I am trying to recreate functionality of similar to adding/editing phone numbers or emails in the contact editing on the iPhone.
I always have an empty row with placeholder text available. In edit mode (push of a button on toolbar) I un-hide UITextField. In 'editing changed' callback I insert a new row into the section, again similar to iPhone contact editing view.
However, after the insert when I start modifying 2nd row (3rd row is inserted as expected) the value of the 1st row text field is cleared to the placeholder value.
I have read somewhere that I would need to store the text field value in row 1, at the time of 2nd row insertion, and on end editing (I assume) otherwise it would be lost? This seems quite strange to me and I was wondering if this is the only way? At what point would I go back to restore it? This of course keeps repeating as I insert a new row and modify the last row's value values in all the rows prior are being cleared.
Can anyone point me to an example of similar to contact editing functionality? If I would change the way rows are inserted by having the last row always be a "+ Add Value" row, would that help? I would not think so.
Also, It would be nice if I could change style of the 1st row from UITableViewCellEditingStyleNone to UITableViewCellEditingStyleDelete, but no matter what i have attempted including toggling editing NO/YES in the middle setting all visible rows to react to ignore transitions I can not get it to work, to have all but last row with UITableViewCellEditingStyleDelete. So I thought ok fine let me have the initial row not able to delete (not what I wanted, but I can live with it).

- 1,357
- 9
- 21
2 Answers
Please confirm, but I am guessing from reading farther that scrolling rows out of view would result in the same problem, so on textFieldDidEndEditing as well as possibly on each insert in my case, needs to be handled to store "new" data in the corresponding entry of the Data storage array for each row. However, in my case without scroll I would probably need to do: - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimat.... for all rows in the section being modified and possibly all visible rows. Confirmation are greatly appreciated.

- 1,357
- 9
- 21
Why reuse at all in your case? If all the rows are on the screen at all times just create a new UITableViewCell for each.
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
configure content to go on it...
[cell.contentView addSubview:WHATEVER_YOU_CREATED];
[cell.contentView sizeToFit];
return cell;
Reusing cells is a way for those that have many rows to reuse the ones no longer visible to conserve resources.

- 330
- 2
- 11
-
MyProfilePropertyCell *cell = [[MyProfilePropertyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCellFromStoryboardId"]; this produces an empty row no custom labels as defined in storyboard. What am I doing wrong? Although the more I think about it the more I think this is not a problem in my case as described in the original problem since I am not scrolling yet and there should not be any reuse. However you are correct I do not need to use reuse of cells if I can get my custom cell to display correctly. – kos Feb 12 '13 at 01:26
-
I guess this is because in my custom implementation of initWithStyle I would have to initialize all of the controls vs it being done by the framework for me when using dequeueReusableCellWithIdentifier? Is there an alternative? – kos Feb 12 '13 at 02:11
-
reuseIdentifier is just that and has nothing to do with the storyboard id. – jeka Feb 20 '13 at 16:43