Estoy tratando de hacer que mi vista de tabla recuerde su última posición, de modo que después de que la aplicación se ejecute nuevamente, se desplazará a esa posición. para hacer esto, en mi método viewWillDisappear:
, obtengo el primer número de fila visible y lo guardo en NSUserDefaults
. entonces en mi viewDidAppear trato de desplazarme a esa fila enviando scrollToRowAtIndexPath
a la vista de tabla. Sin embargo consigo un NSRangeException
:UITableView scrollToRowAtIndexPath
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]: section (0) beyond bounds (0).
cualquier ayuda apreciada. Aquí está el código:
- (void)viewDidAppear:(BOOL)animated
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if ([userDefaults valueForKey:@"content_row"] != nil)
{
int rowToHighlight = [[userDefaults valueForKey:@"content_row"] intValue];
NSIndexPath * ndxPath= [NSIndexPath indexPathForRow:rowToHighlight inSection:0];
[contentTableView scrollToRowAtIndexPath:ndxPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
-(void) viewWillDisappear:(BOOL)animated
{
NSIndexPath *selectedRowPath = [[contentTableView indexPathsForVisibleRows] objectAtIndex:0];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setInteger:selectedRowPath.row forKey:@"content_row"];
}
¿Podría publicar el bit de código que hace la creación scrollToRowAtIndexPath y NSIndexPath? – probablyCorey