如果我是第一次加载应用程序,它会进入正确的调查视图,但是当我通过双击主页按钮关闭应用程序并从iphone底部退出时,然后重新打开应用程序,应用程序崩溃而不是正确转到返回的用户视图控制器,这个视图控制器只是名为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
AppDelegate.m:
#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;
}
谢谢