Что я делаю, так это помещаю целое число в NSUserDefaults для ключа @"navigationDepth"
с указанием его глубины и любой другой информации, такой как индекс редактируемого элемента. Затем, когда приложение запускается, делегат приложения отправляет сообщение для просмотра контроллеров, чтобы выдвинуть соответствующее количество контроллеров представления. Вот пример кода:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
// Restore navigation depth and picture being viewed or edited
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id root = [navigationController topViewController];
int navDepth = [defaults integerForKey:@"navDepth"];
int pictureIndex = [defaults integerForKey:@"currentPictureIndex"];
switch (navDepth) {
case 1:
[root viewImageAtIndex:pictureIndex animated:NO];
break;
case 2:
[root editImageAtIndex:pictureIndex animated:NO];
break;
default:
break;
}
}
Редактировать: вот код для нажатия контроллеров представления:
- (void) viewImageAtIndex:(int)index animated:(BOOL)animated {
if ((0 <= index) && (index < allPictures.count)) {
ViewerViewController *c = [[ViewerViewController alloc] initWithNibName:@"ViewerViewController"];
c.allPictures = self.allPictures;
c.currentPictureIndex = index;
[self.navigationController pushViewController:c animated:animated];
[c release];
}
}
- (void) editImageAtIndex:(int)index animated:(BOOL)animated {
ViewerViewController *c = [[ViewerViewController alloc] initWithNibName:@"ViewerViewController"];
c.allPictures = self.allPictures;
c.currentPictureIndex = index;
[self.navigationController pushViewController:c animated:NO];
[c editPictureWithAnimation:animated]; // Immediately push the editor view controller
[c release];
}