Reputation: 247
i have a tableView with 3 cells.
i want to change .detailTextLabel of that cells after tableView loaded.
how i can do that?
i triad this:
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0];
firstCell.detailTextLabel.text = @"ABC";
[tableView reloadData];
but this is not doing nothing. what the problem?
Upvotes: 0
Views: 564
Reputation: 24
when you say
[tableView reloadData];
that time your : -
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
method will be called for three times as you have 3 cell in your row and this will again override your firstCell.detailTextLabel.text with the original text that you must be providing through your array...
so if you are using array.. then you need to change the object in that array for the required index.
just implement this:
[array replaceObjectAtIndex:0 withObject:@"Change"];
[tableViewCategory reloadData];
hope so this will work for you...
Upvotes: 0
Reputation: 21221
instead of
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0];
use
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
Upvotes: 1
Reputation: 3408
Try this:
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
firstCell.detailTextLabel.text = @"ABC";
no need to call reloadData.
Upvotes: 0