0
votes

I have a UItableView that segues to a different view controller. I'm using a UITapGestureRecognizer that segues back to the tableView. This segue works, but I would like it to segue back to the tableView at the originally selected table row. How do I accomplish this?

Edit: Edited code

- (void)viewWillAppear:(BOOL)animated  {

 appDelegate = [[UIApplication sharedApplication] delegate];
 NSLog(@"%@", NSStringFromCGPoint(appDelegate.testCGPoint));

 [self.tableView setContentOffset:appDelegate.testCGPoint animated:YES];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

 if ([segue.identifier isEqualToString:@"ShowDetail"]) {

   appDelegate.testCGPoint = [self.tableView contentOffset];

 }
}
2

2 Answers

1
votes

You should save the content offset of the table view into a value.
float tableContentOffset;
Then later, save the offset into that float. Finally, when you need to set the content offset of the table view,
[self.tableView setContentOffset:CGPointMake(0,tableContentOffset) animated:YES];

0
votes

So, in your code, you've created a CGPoint. However, the creation existed within the method prepareForSegue. Thus, you cannot access the point outside of the method! A solution to this is to create the CGPoint in the header file.
CGPoint tableContentOffest;
Then in your prepareForSegue method, all you have to do is SET the table's offset value. Don't create a new CGPoint.
Additionally, in your code [vc.tableView setContentOffset:_tableContentOffset animated:YES]; you would want to set it with [vc.tableView setContentOffset:tableContentOffset animated:YES]; and not _tableContentOffset. Hope this helped!