4

所以我有一个 containerView 控制器,它基本上就像 splitViewController 一样。

我正在尝试在 containerViewController 中添加一个 UINavigationController,它工作得很好。

我在情节提要中创建了一个 UINavigationController,其中连接了一堆 UIViewController,所有这些都通过“推送”segues 连接在一起。我从情节提要中取出这个 NavigationController,通过代码将它粘贴到我的 ContainerViewController 中。然后它显示 NavigationController 应该在哪里,我可以单击按钮,并且推送动画仅发生在 ContainerViewController 的 NavigationController 框架内。

但是,如果我从 NavigationController 上的代码调用 popViewController,它将为整个 ContainerViewController 设置动画。我不想要,我希望它只为 NavigationController 设置动画。

有谁知道它为什么这样做?

当你在 ContainerViewController 中有一个 UINavigationController,然后你可以在 NavigationController 上 popViewController,你如何让它只动画 UINavigationController 而不是它所在的整个 ContainerViewController?

4

1 回答 1

1

我也遇到过这个问题。它也影响了我的推动。我的解决方法是使用代码而不是故事板 segues。

- (void) switchToView:(NSString *)identifier {
    UIViewController *target = [self getOrCreateViewController:identifier];
    [self switchToViewController:target identifier:identifier];
}

// If you need to interact with the VC before it is pushed break it into 2 step process
- (UIViewController *) getOrCreateViewController:(NSString *)identifier {
    NSArray *children = [self.viewControllers filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"restorationIdentifier == %@", identifier, nil]];
    UIViewController *target = (children.count > 0 ? children[0] : [self.storyboard instantiateViewControllerWithIdentifier:identifier]);
    return target;
}

// For my use case, I always animate via push. Could modify this to pop/push as appropriate
- (void) switchToViewController:(UIViewController *)target identifier:(NSString *)identifier {
    [self setViewControllers:[self.viewControllers filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"restorationIdentifier != %@", identifier, nil]] animated:NO];
    [self pushViewController:target animated:YES];

}

我知道有点丑陋的解决方法......希望我能找到一个更好的答案(在这里寻找一个)。:-)

于 2012-11-22T15:56:26.210 回答