简体   繁体   中英

Tableview row stays selected after coming back from push segue

My view controller is an UIViewController . I've added UITableView to the UIView . When the tableview row is selected, a push segue fires a new view controller. However, when coming back from the new view controller, the selected row stays selected. I didn't have this problem when my first controller was an UITableviewController , but I had to change it to an UIViewController , because I wanted to add activity indicator to my view. The other thing I noticed is that when my first controller was a UITableviewController , viewDidLoad wasn't called when coming back from the new view controller (but now it's called).

Add...

[tableView deselectRowAtIndexPath:indexPath animated:YES];

in tableView:didSelectRowAtIndexPath:

Try this:

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

This will help you out...

This mechanism, a variation of the suggested answers, removes the selection when the detail view disappears, but also helps the user know what they selected to get to the detail view:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
}

This appears to be what Apple is doing in their own apps. See the behavior when a Contact record is selected in the Contacts app for an example.

You can Add

[tableView deselectRowAtIndexPath:indexPath animated:YES];

in tableView:didSelectRowAtIndexPath: delegate.

Or you can do

-(void)viewWillAppear:(BOOL)animated
{
    [table reloadData];
}

Swift 3.0:

tableView.deselectRow(at: indexPath, animated: true)

tableView.deselectRowAtIndexPath(indexPath, animated: true)

This might help as an updated answer to the question.

Found some information on this topic here. http://www.raywenderlich.com/81880/storyboards-tutorial-swift-part-2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM