Cuando hago clic en un elemento de una determinada lista en mi UITableView, quiero pasar el índice del elemento que hice clic en la siguiente vista detallada.Número de índice de pase entre la lista de UITableView segue
Este es mi código en cuestión hasta el momento:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
HomeworkDetails *view = [[HomeworkDetails alloc] init];
int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
NSLog(@"%u", lastIndex);
[self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
view.currentIndex = lastIndex;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
En este punto, puedo avanzar con éxito a la siguiente ViewController (HomeworkDetails) pero la información no se pasa a través. Estoy tratando de lograr esto haciendo view.currentIndex = lastIndex;
pero esto no está funcionando. ¿De qué otra manera puedo hacer esto? Perdón si me perdí algo; Soy un principiante en el desarrollo de iOS.
Con sugerencias:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
HomeworkDetails *view = [[HomeworkDetails alloc] init];
int lastIndex = [indexPath indexAtPosition:[indexPath length] - 1];
NSLog(@"%u", lastIndex);
[self performSegueWithIdentifier: @"HomeworkDetailsSegue" sender:self];
view.currentIndex = lastIndex;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"HomeworkDetailsSegue"]) {
// note that "sender" will be the tableView cell that was selected
UITableViewCell *cell = (UITableViewCell*)sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; //**error**
HomeworkDetails *vc = (HomeworkDetails*)[segue destinationViewController];
vc.currentIndex = indexPath.row;
}
}
¿El 'currentIndex' está destinado a ser una propiedad en su controlador tableView o en el viewController de destino de segue? – jonkroll
es una propiedad en el ViewController de destino. perdón por la confusion. Además, para probar, básicamente estoy configurando un TextView en el controlador de destino para esta propiedad, pero siempre es 0. – Kgrover