Programmatically selecting a cell in a table view does not perform an associated segment

Well, as I say in the topic, my problem is that I select a cell in the form of a table programmatically with the intention of automatically executing the session associated with it. I have code for this in the viewWillAppear of the table manager associated with it.

As a result, a cell is selected, but the session is not performed. Do you know, why?

By the time I execute segue programmatically on viewWillAppear to solve the problem, but I wonder why segue does not execute automatically if the cell is selected ...

By the way. Segue should be fine, because when I select that clicking on a cell works correctly,

More info: I'm working on a splitview controller. The left side has a tableview controller, and the segue is a viewcontroller on the right side.

Thank you so much!

Carlos

Associated Code:

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

// Si no hay ninguna fila seleccionada, seleccionaremos la primera

// Obtenemos la fila seleccionada
NSIndexPath *filaSeleccionadaPath = [self.tableView indexPathForSelectedRow];

// Si no hay ninguna fila seleccionada
if (!filaSeleccionadaPath)
{
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];

}

}

+3
source share
1 answer

The documentation UITableViewindicates:

Calling this method does not cause the delegate to receive the table View: willSelectRowAtIndexPath: or tableView: didSelectRowAtIndexPath: message and will not send UITableViewSelectionDidChangeNotification notifications to observers.

therefore, it will not cause any action. If you use segues, you can use performSegueWithIdentifier:sender:in a class UIViewController(most likely self). You can specify the identifier and the sending element (most likely, the cell).

+6

All Articles