如何显示登录和关闭设置 - 情节提要

Posted

技术标签:

【中文标题】如何显示登录和关闭设置 - 情节提要【英文标题】:How to display Login and dismiss Settings - Storyboard 【发布时间】:2012-04-24 17:31:37 【问题描述】:

我试图弄清楚如何从注销按钮显示登录(模式视图控制器)并从登录下方自动关闭设置(模式视图控制器)。您可能会看到故事板布局:

http://cl.ly/2B3h0T130S1K1026201N

我尝试将此代码添加到 SettingsViewController.m 中的注销方法中

- (IBAction)logoutAccount 

      [self dismissModalViewControllerAnimated:YES];

      UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
      UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
      [vc setModalPresentationStyle:UIModalPresentationFullScreen];

      [self presentModalViewController:vc animated:YES]; 

 

问题是当我单击注销时它强制我的应用程序冻结。有人知道它有什么问题吗?任何建议表示赞赏。

【问题讨论】:

【参考方案1】:

用户再次登录后,您希望应用在哪里?假设您希望应用位于设置按钮所在的视图控制器中(从情节提要中看起来是这样)。

那么那个vc(导航控制器中的根vc)可以这样做:

- (void)viewDidAppear:(BOOL)animated 

    if (/*login is needed*/) 
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
        [vc setModalPresentationStyle:UIModalPresentationFullScreen];

        [self presentModalViewController:vc animated:YES]; 
     else 
        // normal view did appear logic
    

注销按钮现在可以这样做:

- (IBAction)logoutButtonPressed:(id)sender 
    [self.navigationController popToRootViewControllerAnimated:NO];

【讨论】:

我还有一个关于将 PasscodeViewController 添加到其中的问题。您可能会看到我在***.com/questions/10307120/… 上发布的这个问题,非常感谢您的帮助!谢谢!

以上是关于如何显示登录和关闭设置 - 情节提要的主要内容,如果未能解决你的问题,请参考以下文章

使用情节提要时关闭模式的正确方法是啥?

在 xcode5 中找不到适用于 ios 5 的情节提要 [关闭]

如何在 Storyboard 中显示 UIView [关闭]

情节提要弹出框已关闭,未调用委托方法

尝试更改情节提要中的某些内容时立即关闭

显示带有情节提要的一次性登录屏幕的最佳实践