关于国家维护的问题

时间:2010-01-14 06:14:26

标签: iphone

如果我有10个观看次数,例如从1到2,从2到3,再到10到10

如果我去第5个视图,然后我按主页按钮,然后我去另一个应用程序,然后做了一些任务后,我转到主页按钮然后我按我的应用程序我的第一个视图打开但我想打开我的第5个视图

plzzzzzzzzz告诉我解决方案 等待回复

1 个答案:

答案 0 :(得分:1)

我所做的是在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];
}