willAnimateRotationToInterfaceOrientation 在 vi​​ewWillAppear 之前被调用

发布于 2024-10-08 02:20:53 字数 562 浏览 0 评论 0原文

我刚刚发现我的 iOS 应用程序发生了一次崩溃,它与在 viewWillAppear 之前调用 willAnimateRotationToInterfaceOrientation 有关。

我有一个有两个视图的应用程序。基本上,当 view1 消失时,我释放一些数组,假设它们重新出现在 viewWillAppear 中时将被重新初始化。

但是,如果我更改 view2 中的方向然后切换回 view1,这会导致 willAnimateRotationToInterfaceOrientation 在 vi​​ew1 调用 viewWillAppear 并重新初始化所有内容之前发生,从而导致崩溃。

有没有办法延迟 willAnimateRotationToInterfaceOrientation 直到视图出现并且所有内容都已重新初始化之后?

如果没有,我能看到的唯一解决方案是要么不使用 willAnimateRotationToInterfaceOrientation (这会导致看起来难看的方向变化),要么当我从 view1 切换到 view2 时不释放我的数据,这会导致使用超过必要的内存。

有人对我应该做什么有任何想法吗?

I just tracked down a crash I was having in my iOS app and it is related to willAnimateRotationToInterfaceOrientation being called before viewWillAppear.

I have an app with two views. Basically, when view1 disappears, I release some arrays, assuming they will be re-initialized when it re-appears in viewWillAppear.

However, if I change orientation in view2 then switch back to view1, this causes willAnimateRotationToInterfaceOrientation to happen before view1 has calledviewWillAppear and re-initialized everything and this causes a crash.

Is there any way to delay willAnimateRotationToInterfaceOrientation until after the view has appeared and everything has been re-initialized?

If not, the only solutions I can see are either not using willAnimateRotationToInterfaceOrientation (which results in an ugly looking orientation change) or not releasing my data when I switch from view1 to view2 which results in more memory being used than necessary.

Does anybody have any thoughts on what I should do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

攀登最高峰 2024-10-15 02:20:54

您可以使用延迟加载样式代码来避免您的问题,例如:

NSArray* someData;


-(void)somefun1{

   if (!someData) {

      [self loadData];
   }

    //use your data
}

-(void)somefun2{

    if (!someData) {

    [self loadData];
    }

    //use your data

}

-(void)loadData{
    //some loading code
}

使用延迟加载样式代码您永远不需要介意事件调用顺序。

You can use lazy-loading style code avoid your problem, like:

NSArray* someData;


-(void)somefun1{

   if (!someData) {

      [self loadData];
   }

    //use your data
}

-(void)somefun2{

    if (!someData) {

    [self loadData];
    }

    //use your data

}

-(void)loadData{
    //some loading code
}

use lazy-loading style code you never need mind event calling order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文