开发者

Deselecting a row in table view does not animate

I have a view controller that manages a table view. My understanding is that a table cell will be deselected automatically if I push another viewcontroller and then pop 开发者_如何学编程back to the table view.

However, in the same class (that I use a few times), there is one instance of the class when the cell is deselected but not animated (it'll just turn blue and then back to normal without animating). Why did this happen? I have a few instances of this class but it only happens to one of them. What might be causing this?


From my experience cells are not automatically deselected if you push/pop a view controller (at least not when using a navigationcontroller), unless you add some code te deselect it ! It may also be automatically deselected if you are doing a [tableView reloadData] in viewWill/DidAppear (or in a process started in these methods).

Did you try to add something like that in viewDidAppear ?

NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
if (indexPath != nil) {
    [tableView deselectRowAtIndexPath:indexPath animated:YES]
}


    NSIndexPath *indexPath = [tableView indexPathForSelectedRow];
if (indexPath != nil) {
    [tableView deselectRowAtIndexPath:indexPath animated:YES]
}
  1. this you have to write in didselectRowAtIndexPath method


You can reload the Tableview again.

In your viewWillAppear

[yourTableView reloadData];

Or if you dont want to disturb your Datasource try this

NSArray *array = [yourTableView visibleCells];
for(UITableViewCell *cell in array)
{
    cell.selected = NO;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜