If i have total 10 views such as from 1 to 2, 2 to 3,and same as upto 10
if i go to 5 th view,then i press home button and then i go to another application and then after doing some task ,i go to home button and then i press my application my 1 st view opens but i want to open my 5 th view开发者_开发技巧
plzzzzzzzzz tell me solution for this waiting fo reply
What I do is put an integer in NSUserDefaults for the key @"navigationDepth"
with how deep it is, and any other information such as the index of the item being edited. Then when the app launches, the app delegate sends a message to view controllers to push the appropriate number of view controllers. Here's some sample code:
- (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;
}
}
Edit: Here is the code for pushing view controllers:
- (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];
}
精彩评论