0

我在我的应用程序委托中创建了一个 RootViewController,如下所示:

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

    StartViewController *viewController = [[StartViewController alloc] init];
    StartNavigationController *navigationController=[[StartNavigationController alloc] initWithRootViewController:viewController];
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];
}

当我点击注销按钮时,我想将用户发送回 rootview 控制器:

- (IBAction) logoutButtonPressed:(UIButton *)sender
{
    [Users logOut];

    [self.navigationController popToRootViewControllerAnimated:YES];
}

当我在我的 iPhone 4s 上运行它时效果很好(当它到达时测试 iphone 6),但如果我让用户登录超过一天并单击注销按钮,屏幕会滑到黑色。

为什么我的根视图控制器在 24 小时左右后没有调用我的 startviewcontroller?

4

1 回答 1

1

我试图给出一个答案,我想它应该对你有用。首先,您检查StartViewController它是否存在于 navigationController 堆栈中。根据您的堆栈StartViewController应该是您添加的第一个控制器navigationController

StartViewController *loginController=[self.navigationController.viewControllers objectAtIndex:0];


if(loginController){
   [self.navigationController popToViewController:loginController animated:YES];
}else{
    NSMutableArray *controllers=[[NSMutableArray alloc] init];

   loginController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
    [controllers addObject:loginController];
    [controllers addObjectsFromArray:self.navigationController.viewControllers];
    self.navigationController.viewControllers=[[NSArray alloc] initWithArray:controllers];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

我认为它应该工作。

干杯。

于 2014-11-11T04:48:09.167 回答