我有一个像这样的appDelegate.h:
@property (nonatomic, retain) MyViewController *myViewController;
@property (nonatomic, retain) MyNavigationController *myNavigationController;
我有一个像这样的appDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_myViewController = [[MyViewController alloc] init];
_myNavigationController=[[MyNavigationController alloc] initWithRootViewController:_myViewController];
// self.window.rootViewController = nil;
self.window.rootViewController = _myNavigationController;
[self.window makeKeyAndVisible];
[application setStatusBarHidden:NO];
[application setStatusBarStyle:UIStatusBarStyleDefault];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
return YES;
}
但如果我的手机上有我的应用并在一段时间后退出,rootViewController永远不会被解雇。屏幕只是黑色,而不是在我的myViewController上显示我的蓝色背景。
此外,当应用加载并登录时,屏幕开始黑屏并推送到我的第一个标签栏。请参阅下面的myViewController.m的详细信息:
- (void)viewDidLoad
{
[super viewDidLoad];
// login code returns currentUser if logged in, otherwise not
if (currentUser)
{
// User is logged in
TabBarController *mytab = [[TabBarController alloc] init];
// Hide navigation bar on home page
self.navigationController.navigationBarHidden = YES;
// Presentation
[self.navigationController pushViewController:mytab animated:YES];
}
else
{
// The user is not logged in
[self.navigationItem setHidesBackButton:YES];
self.navigationController.navigationBarHidden = YES;
[self addLoginButtonsAndViewDetails];
}
}
我错过了什么?
(旁注:如果用户已登录,如何像大多数应用程序一样创建在加载后台页面后消失的启动页面?)
我用于在另一个logoutViewController中注销的函数是:
// Should be the first in the stack
MyViewController *loginController = [self.navigationController.viewControllers objectAtIndex:0];
if (loginController)
{
[self.navigationController popToViewController:loginController animated:YES];
}
else
{
NSMutableArray *controllers=[[NSMutableArray alloc] init];
loginController = [[MyViewController alloc] init];
[controllers addObject:loginController];
[controllers addObjectsFromArray:self.navigationController.viewControllers];
self.navigationController.viewControllers = [[NSArray alloc] initWithArray:controllers];
[self.navigationController popToRootViewControllerAnimated:YES];
}
始终调用top if语句,并且永远不会运行else。但是,在我的手机或模拟器上有24小时的应用后,myViewController无法加载。如果你在登录后立即执行它,它可以正常工作。为什么mywinController正确加载?我该如何强制这种情况发生?