Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell: How do I update textLabel.text at fifth row?

I created and fulfilled UITableViewCell. I want to update textLabel.text at fifth row when I pressed UINavigationButton. How can I do this?

UITableViewCell *cell;
cell = [tableView_ dequeueReusableCellWithIdentifier:@"any-cell"];
if(cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"any-cell"] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = leftString;
like image 283
Voloda2 Avatar asked Nov 22 '11 13:11

Voloda2


1 Answers

The direct way is,

NSIndexPath *fifthRow = [NSIndexPath indexPathForRow:4 inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:fifthRow];
cell.textLabel.text = @"the updated text";

But, the better way is to update the dataSource and reload the tableView or just the row.

like image 169
EmptyStack Avatar answered Sep 22 '22 20:09

EmptyStack