When I click an element of a specific list in my UITableView, I want to pass the index of the element I clicked to until the next detailed view.
This is my corresponding code:
- (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]; }
At this point, I can successfully move on to the next ViewController (HomeworkDetails), but no information is being transmitted. I am trying to accomplish this by doing view.currentIndex = lastIndex;
but it does not work. How else can I do this? Sorry if I missed something; I'm starting iOS development.
With suggestions:
- (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"]) {

source share