莫代尔瞄准链 [英] Modal Segue Chain

查看:102
本文介绍了莫代尔瞄准链的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,它具有登录视图( LognnViewController ),一旦用户成功通过身份验证,就会被带到另一个视图(输入一些简单细节的DetailEntryViewController

输入详细信息后,用户将被带到由标签控制器组成的应用程序的主要部分( TabViewController )包含各种其他视图。 LogInViewController执行一个模态segue到 DetailEntryViewController DetailEntryViewController 然后执行一个模态segue到TabViewController所以我有点亲切一个模态segue链进入应用程序。当用户注销时,我想一直回到LogInViewController,但当我这样做时:

  [self.presentingViewController dismissModalViewControllerAnimated:YES]; 

...它弹出TabViewController,我最终返回 DetailEntryViewController 而不是第一个LogInViewController。有没有什么方法可以轻松地回到第一个视图控制器或做这个模态segue链的事情阻止我这样做。我有一个明智的想法是将一些代码放在 DetailEntryViewController viewWillAppear 中:如果用户已经登录,它会自动弹出在 viewWillAppear viewDidLoad :等等

关于如何实现这一目标的任何想法?

解决方案

我认为这是不是实现您的应用程序的最佳结构。模态控制器应该用于暂时中断程序流程,因此使用模态来获取主要内容并不理想。我这样做的方法是让你的标签栏控制器成为窗口的根视图控制器,然后在第一个标签的控制器中,从viewDidAppear方法以模态方式显示登录控制器,这样它就会立即出现(你会看到它)除非取消选中segue属性检查器中的动画框,否则将显示第一个选项卡的视图。显示那个细节控制器,然后关闭两个模态控制器以返回到您的主要内容。当用户注销时,只需再次显示该登录控制器。我这样实现了这个想法。在第一个标签的视图控制器中:

   - (void)viewDidLoad {
[super viewDidLoad];
_appStarting = YES;
}

- (void)viewDidAppear:(BOOL)动画{
[super viewDidAppear:animated];
if(_appStarting){
[self performSegueWithIdentifier:@Loginsender:self];
_appStarting = NO;
}
}

然后在最后一个(在你的情况下为第二个)模态查看控制器,我有一个按钮方法:

   - (IBAction)goBackToMain:(id)sender {
[self .view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}


I have an iOS app that has a log in view (LognnViewController) and once a user is successfully authenticated they are taken to another view (DetailEntryViewController) to enter some simple details.
Once the details are entered the user is taken to the main part of the app that consists of a tab controller (TabViewController) that holds a variety of other views. The LogInViewController performs a modal segue to the DetailEntryViewController and the DetailEntryViewController then performs a modal segue to the TabViewController so I have kind of a modal segue chain going to get into the app. When a user logs out I want to go all the way back to the LogInViewController but when I do a:

[self.presentingViewController dismissModalViewControllerAnimated:YES];

...it pops the TabViewController and I end up back at the DetailEntryViewController instead of the first LogInViewController. Is there any way I can pop back to the first view controller easily or does doing this modal segue chain thing prevent me from that. I got the bright idea to put some code in the DetailEntryViewController viewWillAppear: that would automagically pop itself if the user had logged out but apparent making calls to dismiss a modal controller are not allowed in viewWillAppear: viewDidLoad:, etc.

Any ideas on how to make this happen?

解决方案

I think this is not the best structure to implement your app. Modal controllers are supposed to be for temporary interruptions to the flow of the program, so using a modal to get to your main content is not ideal. The way I would do this is to make your tab bar controller the root view controller of the window, and then in the first tab's controller, present the login controller modally from the viewDidAppear method, so it will appear right away (you will briefly see the first tab's view unless you uncheck the "animates" box in the segue's attributes inspector). Present the details controller from that one, and then dismiss both modal controllers to get back to your main content. When the user logs out, just present that login controller again. I implement this idea like this. In the first tab's view controller:

- (void)viewDidLoad {
    [super viewDidLoad];
    _appStarting = YES;
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (_appStarting) {
       [self performSegueWithIdentifier:@"Login" sender:self];
        _appStarting = NO;
    }
}

Then in the last (second in your case) modal view controller, I have a button method:

-(IBAction)goBackToMain:(id)sender {
    [self.view.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}

这篇关于莫代尔瞄准链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆