iphone - 如何显示登录和关闭设置 - Storyboard

标签 iphone objective-c ios authentication storyboard

我想弄清楚如何从注销按钮显示登录(模态视图 Controller )并从登录下方自动关闭设置(模态视图 Controller )。您可能会看到 Storyboard布局:

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

} 

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

最佳答案

用户再次登录后,你希望应用在什么位置?假设您希望应用位于设置按钮所在的 View Controller 中(从 Storyboard 中看起来就是这样)。

然后那个vc(导航 Controller 中的根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];
}

关于iphone - 如何显示登录和关闭设置 - Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10302992/

相关文章:

Iphone:如何在 Objective C 中创建 json

iphone - UISearchDisplayController-如何禁用自动搜索

iOS 和界面生成器 : misplaced view (e. g。 UITableViewCell)

ios - 通过触摸按钮显示广告横幅

iphone - 如何更改 iphone 中标题的字体大小?

ios - 如何让 UITableView 忽略 UINavigationController

ios - 如何在 ui 搜索栏中的 x 按钮操作事件上 resignfirstResponder?

iPhone:如何知道 UISlider 是否在滑动?

objective-c - CAGradientLayer 作为 UIView 的图层类

ios - 具有 T-Z 时间格式的 NSDateFormatter