Pregunta

Por lo tanto, tengo una vista de uable, y las celdas están conectadas a un UistoryBoardsegue para abrir un nuevo UIViewController. Después de hacer clic en una celda prepareForSegue Se llama y todo funciona bien.

PREGUNTA: En el método de Follwoing, ¿cómo puedo saber cuál es el inexpático de la celda seleccionada en mi vista de tabla?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ObjectDetailViewController *mvc = [segue destinationViewController];
    // PassingObject *obj = [self.array objectAtIndex: ? ];
    mvc.passingObject = obj;
}
¿Fue útil?

Solución

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Assume self.view is the table view
    NSIndexPath *path = [self.tableView indexPathForSelectedRow];
    DetailObject *detail = [self detailForIndexPath:path];
    [segue.destinationViewController setDetail:detail];
}

Otros consejos

En lugar de [self.TableView indexpathForSelectedRow] (mire la respuesta djplayer) puede usar [self.tableview indexpathforcell: remitente], ya que el remitente es una celda seleccionada en este caso.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top