【问题标题】:nested push animation can result in corrupted navigation bar PUSH POP PUSH嵌套推送动画会导致导航栏损坏 PUSH POP PUSH
【发布时间】:2013-11-22 02:12:54
【问题描述】:

我有三个控制器第一,第二,第三。首先是navigationController的rootViewController。

SecondViewController 中,我有一个名为 SecondViewControllerDelegate 的协议,它有一个委托方法

@protocol SecondViewControllerDelegate <NSObject>

- (void)doneSucceed:(NSString *)msg;

@end

在FirstViewController中,我有一个按钮,当点击它时,执行以下操作

[self.navigationController pushViewController:_s animated:YES];

_s 表示 SecondViewController,其委托是 F​​irstViewController

在 doneSucceed 方法中执行以下操作

- (void)doneSucceed:(NSString *)msg
{
    NSLog(@"%@", msg);
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController pushViewController:_t animated:YES];
}

然后是错误

嵌套推送动画可能导致导航栏损坏 显示,有人告诉我为什么吗?谢了

【问题讨论】:

    标签: ios iphone


    【解决方案1】:

    问题是你调用 pop 和 push 动画背靠背。在 iOS6 中,推送调用基本上被忽略,但在 iOS7 中,推送是在弹出动画时调用的,因此它们是“嵌套”的,您会得到以下结果:

    nested push animation can result in corrupted navigation bar show
    

    您可以从 SecondViewController 进行 pop 调用,而不是在 doneSucceed 中弹出。然后等待FirstViewController的viewDidAppear推送ThirdViewController。您可以使用 doneSucceed 方法来切换是否应该在 viewDidAppear 上转换到 ThirdViewController

    【讨论】:

    【解决方案2】:

    将导航控制器假设为视图控制器堆栈。

    [self.navigationController popViewControllerAnimated:YES];
    

    确实从堆栈中弹出视图控制器。现在视图控制器无效。并且从您正在调用的无效视图控制器

    [self.navigationController pushViewController:_t animated:YES];
    

    因此,由于它是一个堆栈,所以中间的值是无效的,并试图将一个值从无效的中间值推到顶部

    如果 1,2,3 是堆栈的成员,则删除 2 是可以的,但删除的 2 正在尝试将 3 添加到 2 之上,并且由于 2 尚未在堆栈中,因此无法正确添加 3

    【讨论】:

      【解决方案3】:

      也可以通过设置 navigationController 的 viewControllers 属性来做你想做的事情

      NSMutableArray* controllers = [[self.navigationController viewController] mutableCopy];
      [controllers removeLastObject];
      [controllers addObject:_t];
      [self.navigationController setViewControllers:controllers animated:YES]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 2011-09-19
        相关资源
        最近更新 更多