关闭模态视图然后执行segue以打开第二个模态视图

时间:2012-05-04 15:19:29

标签: ios cocoa-touch modalviewcontroller uistoryboard uistoryboardsegue

我有一个允许用户登录和注册的HomeController。如果用户单击登录,我使用segue打开模态视图。

在模态视图中有一个按钮,表示注册。所需操作是关闭登录模式视图,然后使用performSegueWithIdentifier:

打开注册模式视图
- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender
{
    NSLog(@"loginControllerDidRegister");
    [self dismissViewControllerAnimated:YES completion:nil];
    [self performSegueWithIdentifier:@"RegistrationSegue" sender:sender];
}

这正确地取消了模态视图,然后调用performSegueWithIdentifier:,其中我有记录代码,显示它被调用,就像我按下了注册按钮一样。

我认为登录模态视图消失的动画可能会干扰第二个模态视图的显示。关于如何解决这个问题的任何想法?

3 个答案:

答案 0 :(得分:2)

你需要启动你的“第二模态”vc。这就是“prepareForSegue:”方法的作用。你还需要覆盖“perform:”方法。这比你想象的要复杂一点。如果有帮助,这里是一个细分如何工作的细分......

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;

被调用并传入“segue”。在幕后

- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)source;

被调用,这就是创建“segue”的地方。

“segue”对象具有

的属性
(NSString *)identifier
(UIViewController *)sourceViewController
(UIViewController *)destinationViewController

没有这些,不能进行。这些类似于手动分配视图控制器

SomeViewController *secondView = [SomeViewController alloc] initwithNibName:@"SomeViewController" bundle:nil];

然后

[[segue destinationViewController] setModalTransitionStyle:UIModalTransitionStyle(...)];

这是......

secondView.modalTransitionStyle = UIModalTransitionStyle(...);

(...)将是故事板中选择的“segue”转换。

最后

[[segue sourceViewController] presentModalViewController:destinationViewController animated:YES];

只是

[self presentModelViewController:secondView animated:YES];

是让一切成为现实的原因。你基本上必须调整那些引人注目的东西,以获得你想要的工作,但它是可行的。

答案 1 :(得分:0)

您必须将第二个模态视图控制器的performSegue放在dismissViewControllerAnimated调用的完成块中。当UINavigationController仍然呈现其他模态视图控制器时,它无法处理该演示文稿。

答案 2 :(得分:0)

如果有人有同样的问题。

- (void)loginControllerDidRegister:(LoginController *)controller sender:(id)sender
{
    NSLog(@"loginControllerDidRegister");
    [self dismissViewControllerAnimated:YES completion:^{
        [self performSegueWithIdentifier:@"RegistrationSegue" sender:sender];
    }];  
}
相关问题