Iphone 如何根据现有用户或返回用户(iOS)在应用程序启动时加载不同的视图?

Iphone 如何根据现有用户或返回用户(iOS)在应用程序启动时加载不同的视图?,iphone,ios,Iphone,Ios,如果我第一次加载应用程序,它会进入正确的调查视图,但当我双击iphone底部的home按钮关闭应用程序并退出时,然后重新打开应用程序,应用程序会崩溃,而不是正确进入返回的user view controller,此视图控制器名为viewController,测量控制器名为surveyViewController 以下代码不起作用: AppDelegate.h: #import <UIKit/UIKit.h> @class ViewController; @class SurveyV

如果我第一次加载应用程序,它会进入正确的调查视图,但当我双击iphone底部的home按钮关闭应用程序并退出时,然后重新打开应用程序,应用程序会崩溃,而不是正确进入返回的user view controller,此视图控制器名为viewController,测量控制器名为surveyViewController

以下代码不起作用:

AppDelegate.h:

#import <UIKit/UIKit.h>

@class ViewController;
@class SurveyViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) SurveyViewController *home;
@property (strong, nonatomic) ViewController *home2;

@property (nonatomic, retain) UINavigationController *navController;
@property (nonatomic, retain) UINavigationController *navController2;
@property (strong, nonatomic) ViewController *viewController2;
@property (strong, nonatomic) SurveyViewController *viewController;

@end

谢谢你

你能再解释一下吗?到目前为止,我只能猜测ViewController类中存在错误。您收到的错误消息是什么?应用程序只是崩溃并自行关闭,根本没有错误报告。如果我只是尝试将该视图加载为主屏幕,而不使用surveyviewcontroller,那么viewController类就可以工作。如果还有什么可以帮助您回答这个问题,请告诉我。OT:不要忘记同步您的NSUserDefaults:`[[NSUserDefaults standardUserDefaults]synchronize]`rayfleck-同步对nsuserdefaults有什么作用?如果您在调试中运行此程序,您应该会看到日志中出现崩溃或异常。有关详细信息,您可以添加异常断点:
#import "AppDelegate.h"

#import "ViewController.h"
#import "SurveyViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize viewController2 = _viewController2;
@synthesize home, home2, navController, navController2;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasFilledSurvey"] == NO) {

        home = [[SurveyViewController alloc] initWithNibName:@"SurveyViewController" bundle:nil];
        self.navController = [[UINavigationController alloc]initWithRootViewController:home];
        self.window.rootViewController = self.navController;

        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasFilledSurvey"];

    }
    else {

        home2 = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
        self.navController2 = [[UINavigationController alloc]initWithRootViewController:home2];
        self.window.rootViewController = self.navController2;

    }

    [self.window makeKeyAndVisible];
    return YES;
}