Reputation: 1338
I am trying to update a UITableViewCell
's detail text according to a selection from a UIPickerView
in a Modal View presented when the cell is clicked.
The Modal View pops up when the user clicks a cell in the parent view, then he is being presented with a UIPickerView
and when he is done selecting he's desired value, the user clicks the "save" button. After the user clicks the "save" button the Modal View goes away, and the text of the detail label on the cell in which he clicked gets updated with the value he selected with the Modale View's UIPickerView
.
Unfortunately I can't think of a good, clean, way to do that... I am new to iOS programming and I would like to know if there is any "traditional" way of doing that, I would also appreciate any other way of achieving this.
Thank you very much!
Upvotes: 2
Views: 3102
Reputation: 27147
If you know the indexPath
that prompted the modal view, and you should, it may be tempting to simply grab reference to the cell and change the detailTextLabel
directly like so:
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text = newTextValue;
But this is not the best because it doesn't necessarily reflect the state of the model and provides no animation. The best thing to do is make sure to update the model data that backs your tableview and then do something like this:
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationRight];
There are many UITableViewRowAnimation...
s to choose from including none, but animation helps the user see that they actually made a change.
Upvotes: 3