views:

67

answers:

1

Hey guys,

Is there anyway of renaming a specific cell's text? I know what the row number is, but I don't know how to change the cell title. Any help would be appreciated.

Thanks,

Kevin

+2  A: 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = "new text";
titaniumdecoy
What if it was a custom uitableviewcell? And I don't believe this code works. I have tried it but the name stays the same. I'm doing this in my cellForRowAtIndexPath... the value of the row is in an int variable.
Kevin
I updated my answer a few times, so you should try it now. You don't need this in your cellForRowAtIndexPath method; that's where the cell itself is created. If you want to change it later you should use this code elsewhere.
titaniumdecoy
As for custom UITableViewCells, it depends on how the cell was created. If it doesn't use the textLabel property to display its text, you will have to look at its implementation to determine how to update its content.
titaniumdecoy
If the UITableViewCell cell does not immediately update its content you may need to call [cell setNeedsDisplay].
titaniumdecoy
If you have a custom cell then you would cast the results of the callForRowAtIndexPath: to your particular type of cell, since that is what the table view will give you...
Kendall Helmstetter Gelner