gpt4 book ai didi

iOS7 UINavigationController pushViewController :animated back to back with animation locks up the main thread

转载 作者:行者123 更新时间:2023-12-01 16:46:20 33 4
gpt4 key购买 nike

据我所知,似乎插入 UINavigationController背靠背动画在 iOS7 上造成了死锁。

我最初在 iOS6 上遇到崩溃并想出了以下解决方案:

  • 创建一个 View Controller 数组以在初始推送后推送到导航 Controller 。因此,如果要推送三个 View Controller (A、B 和 C),那么这个数组将有 B 和 C。
  • 实现UINavigationControllerDelegatenavigationController:didShowViewController:animated:
  • 在委托(delegate)方法中,只需检查 View Controller 数组中是否有更多元素。如果是这样,从其中取出第一个元素并将其推送到导航 Controller 中。
    所以本质上如果有 B 和 C View Controller 被推送,navigationController:didShowViewController:animated:将被调用 3 次;每次从 A 开始推送 View Controller 之后。显然,最后一次调用不会做任何事情,因为此时数组应该是空的。

  • 请注意,这种方法在 iOS6 上运行良好。但是,这在 iOS7 中中断了。似乎当它尝试在第二次推送中设置动画时,应用程序卡住了。在深入挖掘之后,我想出了在委托(delegate)实现中以以下方式推送第二个 View Controller 的解决方案。
    dispatch_async(dispatch_get_main_queue(), ^{
    [navigationController pushViewController:viewController
    animated:YES];
    });

    这似乎解决了这个问题,但我想知道是否有人经历过类似的事情并对到底发生了什么有更好的解释。

    最佳答案

    我不确定你遇到了什么问题。我创建了一个具有导航 Controller 和其他四个 Controller 的测试应用程序。第一个 Controller 有一个按钮可以推送到第二个 Controller ,即 FirstPushedViewController。在那个 Controller 中,我有这段代码来推送接下来的两个 Controller ,它在 iOS 7 中运行良好:

    @interface FirstPushedViewController ()
    @property (strong,nonatomic) NSMutableArray *vcs;
    @end

    @implementation FirstPushedViewController

    - (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
    UIViewController *orange = [self.storyboard instantiateViewControllerWithIdentifier:@"Orange"];
    UIViewController *red = [self.storyboard instantiateViewControllerWithIdentifier:@"Red"];
    self.vcs = [@[red,orange] mutableCopy];
    }

    -(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.vcs.count > 0) {
    [self.navigationController pushViewController:self.vcs.lastObject animated:YES];
    [self.vcs removeLastObject];
    }
    }

    关于iOS7 UINavigationController pushViewController :animated back to back with animation locks up the main thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19714288/

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