1

在我的 iphone 应用程序中,我有两个场景,它们都是视图控制器。通常初始场景设置为第一个。当用户播放时,它会传递给第二个。

此时,当用户关闭应用程序并重新启动它时,如果用户已经玩过,它应该从第二个场景开始,因此该用户的初始场景应该改变。

我怎样才能做到这一点?

而且我不使用导航控制器。

4

1 回答 1

4

如果您使用的是 xibs,请在应用程序 delegates 中进行设置 applicationDidFinishLaunchingWithOptions

创建一个全局 BOOL 并在应用程序启动时检查它的值,例如:

。H

@class ViewController;
@class SecondViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) SecondViewController *SecondViewController;

.m

#import "ViewController.h"
#import "SecondViewController.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if (isSecondViewControllerBool == YES) {
        self.SecondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    }else{
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

对于故事板:

在第一个视图控制器viewDidLoad中。

- (void)viewDidLoad
{
    if (isSecondViewControllerBool == YES) {
        UIViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"mySecondViewController"];
        [self presentViewController:secondVC animated:NO completion:nil];

    }else{
        //present normally
    }
}

如果您正在使用情节提要并决定使用我的 xib 解决方案,请从项目中删除情节提要,并在此处将其删除:

在此处输入图像描述

于 2012-07-26T14:36:39.757 回答