开发者

UITableCell - How do I turn off the selected state of the cell when user navigates back to view?

I think this is a very common situation, but I can't find how everybody else solves the problem.

I have a UITableView, and when a user taps a cell I push a new view controller (using UINavigationController) on the stack. When the user taps "B开发者_开发技巧ack" on the navigation bar, the cell still appears in selected state (i.e. blue background).

I want the background to be blue initially, when the user tapped the cell, but to be turned off when the page is shown again.


you could deselect the cell before or after you have pushed the new viewcontroller.

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
    // create and push new viewController
}


There are two ways you can do the same thing:

Either Reload the whole Table in View will Appear

-(void)viewWillAppear:(BOOL)animated{

   [super viewWillAppear:animated];

   [YourTableView reloadData];

}

OR Either

-(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [YourTableView deselectRowAtIndexPath:indexPath animated:YES];
}

Looking at performance wise second one is best solution to use.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜