UITableViewCell: how to update textLabel.text in the fifth line?

I created and executed a UITableViewCell. I want to update textLabel.text in the fifth line when I hit 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; 
+6
source share
2 answers

Straight way:

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

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

+14
source

You can tell UITableView update this line (using reloadRowsAtIndexPaths:withRowAnimation: in a method that handles button changes.

Then you have a special case in your UITableViewDataSource cellForRowAtIndexPath: method.

EDIT: I deleted this answer after seeing @EmptyStack's answer, which looked good to me. Perhaps this answer will cover his proposal to update the DataSource?

0
source

Source: https://habr.com/ru/post/902110/


All Articles