gpt4 book ai didi

iphone - UINavigationController:willShowViewController 问题

转载 作者:可可西里 更新时间:2023-11-01 05:38:56 25 4
gpt4 key购买 nike

我对这个委托(delegate)消息感到困惑。我在 PopupViewController 中有一个导航 Controller 。当我推送一个新的 viewController 时,我不想在推送新 View Controller 之前知道它当前显示的 viewController 是什么......

我已经尝试获取 navigationController.topViewController 和 navigationController.visibleViewContrller,但它们总是等于将要被推送的 viewController...看起来我在之后 View 被推送

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
UIViewController *currentViewController = navigationController.topViewController;
if(currentViewController == viewController){
/// THIS IF STATEMENT IS ALWAYS TRUE
}
}

有没有人偶然发现类似的东西?

最佳答案

UINavigationController Class Reference 中做了一些挖掘看起来你可以使用 viewControllers UINavigationController 的属性(property)类。

Root View Controller (导航堆栈的底部)位于索引 0,后 View Controller (刚刚覆盖的那个)位于索引 n-2topViewController属性位于索引 n-1,其中 n 是数组中 View Controller 的数量。

从 iOS 7 和 Xcode 5.x 开始,您现在可以将 firstObject 消息发送到 viewControllers 属性返回的数组以获取 Root View Controller 。同样,可以通过将 lastObject 消息发送到 viewControllers 属性返回的数组来访问 topViewController 属性。

关于iphone - UINavigationController:willShowViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7421713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com