ECSliding,更改underLeftViewController

时间:2013-06-01 12:09:07

标签: iphone ios objective-c ecslidingviewcontroller

我正在使用ECSliding,我遇到了这个问题!

在我的项目中有以下文件:

InitViewController (ECSlidingController)

FirstViewController (UIViewController)

SecondViewController (UIViewController)

LeftMenuViewController (UIViewController)

LeftMenuTwoViewController (UIViewController)

我使用InitView将我的FirstView作为topview进行实例化。

向右滑动显示LeftMenuViewController,它有一个按钮,如果按下则将topview更改为SecondViewController。我想知道是否可以使用LeftMenuTwoViewController作为SecondView的underLeftViewController。另外我想在LeftMenuTwo中使用一个按钮将topView更改为FirstView。

我想将一个带有underLeftViewController的FirstView作为LeftMenuViewController,将SecondView与underLeftViewController作为LeftMenuTwoViewController。每个菜单都有一个按钮,可以使用不同的underLeftViewController将topView更改为另一个。

我这样做了:

SecondViewController *second =  [self.storyboard
                                  instantiateViewControllerWithIdentifier:@"SecondTop"];

[self.slidingViewController anchorTopViewOffScreenTo:ECRight
                                          animations:nil
                                          onComplete:^{
    self.slidingViewController.topViewController = second;

    [self.slidingViewController resetTopViewWithAnimations:nil
                                                onComplete:^{
        LeftMenuTwoViewController *newUnderLeftVC = [self.storyboard
                                  instantiateViewControllerWithIdentifier:@"LeftTwo"];

        self.slidingViewController.underLeftViewController = newUnderLeftVC;
    }];
}];

但是当我按下按钮时,topView通过向右滑动启动弹跳动画,但永远不会再次返回,并且在TopView离开屏幕后立即显示underLeftViewController变为空白。谁知道为什么?

下载:My Project

1 个答案:

答案 0 :(得分:1)

将方法更改为:

-(IBAction)openSecond:(id)sender
{
    SecondViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"Second"];
    ECSlidingViewController *slideController = self.slidingViewController;

    [slideController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
        slideController.topViewController = second;
        [slideController resetTopViewWithAnimations:nil onComplete:^{

            LeftMenuTwoViewController *newUnderLeftVC = [self.storyboard instantiateViewControllerWithIdentifier:@"LeftTwo"];
            slideController.underLeftViewController = newUnderLeftVC;
        }];
    }];
}

问题在于当视图将自身移除为顶视图控制器时,调用self.slidingViewController不再返回有效实例(它返回nil)。