Deselect row in UITableView, which is a preview

I have a UITableView that is added to the view as a preview. When you select a row, a new view will be present with pushViewController:, and the user can click the back button to return to the UITableView, but then the cell is still selected.

Is there a way to deselect when a view appears?

I read that I have to use the following code, but I cannot get it to work. No errors, no warnings, nothing.

[tableProgram deselectRowAtIndexPath:[tableProgram indexPathForSelectedRow] animated:NO];

+3
source share
3 answers

You must deselect the row in the didSelectRowAtIndextPath method of the delegate of your UITableView. It should look something like this.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    /* initialize your view controller here v and then push it */
    SomeViewController *v = [[[SomeViewController alloc] init] autorelease];
    [self.navigationController pushViewController:v animated:YES];
}

didDeselectRowAtIndextPath - , intelisense.

+9

, , viewDidAppear

- (void)viewDidAppear:(BOOL)animated

NSIndexPath *indexPath = [tableView indexPathForSelectedRow];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

, , , .

+2

quote SimonBS:

, ( ), , viewDidAppear: (BOOL) viewWillAppear: (BOOL) , .

honcheng

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

    NSIndexPath *indexPath = [self.tableViewOutlet indexPathForSelectedRow];

    [self.tableViewOutlet deselectRowAtIndexPath:indexPath animated:YES];

}

you just need to use it in a TableView control. (For example: if you have an xib file with the TableView subzone inside the view, you just need to go to the corresponding code of the view controller and override viewWillAppear, I just did it and it works! Hello visual cue!)

0
source

All Articles