Pregunta

I have a project with a TabBar Controller with a Navigation Controller and other View Controllers on it.

In my Navigation controller i have a sequence of 3 view controller and the last of them, DetailViewController, is being presented using a modal transition. I'm parsing strings between my 2nd and 3rd view controllers, but my labels displaying the information on the 3rd one only display after selecting a cell twice, and the information that shows is the one corresponding to the first selection of the cell.

Heres my 2nd view controller (ViewController) method prepareForSegue:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     titulo=[nomeEvent objectAtIndex:indexPath.row];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
     if ([segue.identifier isEqualToString:@"nextView"]) {
          DetailEventViewController *myVC = [segue destinationViewController];
          myVC.tituloEvento = titulo;
     }
}

The property tituloEvento is declared in the second view controller's .h and in viewwillappear I set my labels text.

¿Fue útil?

Solución

This might be happening because prepareForSegue is getting called before didSelectRowAtIndexPath:. Here is what I would do:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
     if ([segue.identifier isEqualToString:@"nextView"]) {
          DetailEventViewController *myVC = [segue destinationViewController];
          NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
          myVC.tituloEvento = [nomeEvent objectAtIndex:selectedIndexPath.row];
     }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top