0

我正在实现一种级联菜单。

在我的故事板中,我UINavigationController有一个UIViewController作为根视图控制器的(假设它是一个MyViewController)。MyViewController有一个情节提要 ID:“菜单”。
由于此控制器是一个菜单,因此它显示一个 tableView。单击单元格时,会触发一些代码,尤其是:

UINavigationController *menuNavigator = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];
MyViewController *newMenu = (MyViewController*)menuNavigator.topViewController;
//Some configurations of newMenu
[self.navigationController pushViewController:newMenu animated:YES];

因为这里一切正常。

在子菜单中,最后一个单元格是“后退”单元格。当用户触摸它时,它会触发代码:

[self.navigationController popViewControllerAnimated:YES];

我在上一个菜单上正确返回,但没有动画。

我也试过:

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];

但我仍然没有动画。

在情节提要上,我的导航控制器设置为不显示导航栏。如果我显示它,然后触摸自动出现的“后退”按钮,结果是一样的:没有动画。

我的代码有什么问题?

编辑
我正在使用 Autolayout 和 ARC;

4

1 回答 1

0

编辑:你有一些有趣的事情发生。这行代码看起来不对:

UINavigationController *menuNavigator = (UINavigationController*)[self.storyboard instantiateViewControllerWithIdentifier:@"Menu"];

看起来您尝试通过实例化视图控制器来获取导航控制器。我不明白你为什么需要这样的导航器。您可以简单地使用self.navigationController.

我做了类似的事情,我的代码如下所示。

在该didSelectRowAtIndexPath:方法中,我不通过情节提要对象进行实例化,而是执行以下操作:

    DVSecondTableViewController *vc = [[DVSecondTableViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];

要返回,我只使用导航控制器提供的返回按钮,所以我无法帮助您。

于 2014-02-12T13:50:20.027 回答