darbid
darbid

Reputation: 2721

Update UITableViewCell labelText text issues

After a UITableView has been done, I have a async process which updates the text of 1 cell.

The update changes the text and colour e.g.

cell.textLabel.text = @"new text"; 
aCell.textLabel.textColor = [UIColor blackColor];

the issue I have is that these things are called but the cell seems to take seconds to actually change.

Even if I also call

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:cIndex] withRowAnimation:UITableViewRowAnimationMiddle];

The animation happens with the same delay.

Does anyone have an ideas why the cell is taking so long to update OR can anyone point me into the right direction about how to debug what is happening. No other code is running the app is just sitting there so the UI Thread is not busy.

Upvotes: 1

Views: 193

Answers (1)

βhargavḯ
βhargavḯ

Reputation: 9836

Try this way to update UI as you are using async process

dispatch_async(dispatch_get_main_queue(), ^{
     [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:cIndex] withRowAnimation:UITableViewRowAnimationMiddle];
});

EDIT

As per GDC Reference

dispatch_async submits a block for asynchronous execution on a dispatch queue and returns immediately.

So above block of code will get executed immediately on main queue asynchronously so as to update UI.

Upvotes: 3

Related Questions