【问题标题】:UINavigationController inside of a ContainerViewController popView's funkyContainerViewController popView 中的 UINavigationController 很时髦
【发布时间】:2012-05-09 20:13:44
【问题描述】:

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

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

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

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

有人知道为什么会这样吗?

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

【问题讨论】:

  • 你找到解决方案了吗?

标签: ios view controller navigation containers


【解决方案1】:

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

- (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-26
  • 1970-01-01
  • 2018-01-21
  • 2021-06-16
  • 1970-01-01
  • 2011-12-11
  • 2014-09-18
  • 1970-01-01
  • 2016-02-16
相关资源
最近更新 更多