在进行模态segue时使用错误的presentViewController(使用ECSlidingViewController)

时间:2013-05-24 09:55:48

标签: ios xcode storyboard modalviewcontroller ecslidingviewcontroller

我从登录视图控制器以模态方式显示注册视图控制器。我的初始视图控制器是登录视图控制器,当我以模态方式呈现注册视图控制器时,没有任何错误,但是当我使用ECSlidingViewController在注销时重置顶视图时出现了错误。我在注销时使用以下代码将顶视图重置为登录视图控制器。

UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"Login"];
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
    self.slidingViewController.topViewController = newTopViewController;

    [self.slidingViewController resetTopView];

}];

当我使用ECSlidingViewController重置顶视图后以模态方式显示注册视图时,注册视图控制器的presentViewController属性被设置为另一个视图控制器,而不是登录视图控制器。

我知道很难掌握问题的本质,但如果有人需要更多细节以便他们可以回答这个问题,请随意:)

1 个答案:

答案 0 :(得分:1)

ECSlidingViewController确实似乎与presentingViewController混乱。

ECSlidingViewController拥有属性topViewController,您应该能够从那里访问您期望成为presentingViewController的视图控制器。

我能够访问您期望presentingViewController的视图控制器,如下所示:

ECSlidingViewController *ec = (ECSlidingViewController*)self.presentingViewController;
if(ec) {
    UINavigationController *navController = (UINavigationController*)ec.topViewController;

    if(navController && navController.viewControllers.count) {

        UIViewController *top = navController.viewControllers[0];

        // now you'll need to cast top to your presenting view controller's class, eg:
        MyViewController *myVc = (MyViewController*)top;
        [myVc doSomething];
    }
}

您可能没有在您的应用程序中使用导航控制器,在这种情况下它将是这样的(未经测试):

ECSlidingViewController *ec = (ECSlidingViewController*)self.presentingViewController;
if(ec) {
    UIViewController *top = (UIViewController*)ec.topViewController;

    if(vc) {            
        // now you'll need to cast top to your presenting view controller's class, eg:
        MyViewController *myVc = (MyViewController*)top;
        [myVc doSomething];
    }
}