1

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

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

} 

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

4

1 回答 1

0

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

然后那个 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];
}
于 2012-04-24T18:29:44.750 回答