ios - 注销 ios 应用程序并返回到 RootViewController

标签 ios objective-c parse-platform uinavigationcontroller rootview

我在我的应用委托(delegate)中创建了一个 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];
}

当我点击注销按钮时,我想将用户发送回 Root View Controller :

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

    [self.navigationController popToRootViewControllerAnimated:YES];
}

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

为什么我的 Root View Controller 在大约 24 小时后没有调用我的 startviewcontroller?

最佳答案

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

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];
}

我认为它应该有效。

干杯。

关于ios - 注销 ios 应用程序并返回到 RootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26838951/

相关文章:

ios - 自定义字体未显示在新 Storyboard中

ios - 识别 UITableViewCell 中的 UIButton 不起作用 - Swift

ios - 如何将推送通知发送到安装在 mdm 上的 iOS 应用程序?

ios - 发生 IBAction 时 Swift addsubview 和应用程序崩溃

iOS - 在 NSMutableArray 中打乱/随机化对象的顺序

iOS 和 GIT 损坏的 Storyboard

ios - 如何返回一个零自定义 UITableViewCell

ios - 解析 - 从关系中获取对象

iphone - 如何将 UISegmentedControl 合并到 UITabBarController 中?

javascript - 在 session 或注销上删除之前解析服务器