gpt4 book ai didi

objective-c - 如何处理由于内存不足导致页面卸载的情况

转载 作者:行者123 更新时间:2023-11-28 23:12:54 24 4
gpt4 key购买 nike

//In App Delegate
UserProfileTableViewController *uptvc = [[UserProfileTableViewController alloc]init];
UITabBarItem *tempTabBarItem4 = [[UITabBarItem alloc]initWithTitle:@"Fans" image:nil tag:FANSTAB_INDEX];

//I am setting the user id information here directly in app delegate
uptvc.userId = [[UserStockInfo sharedUserStockInfo]getUserId];
UINavigationController *navconUptvc = [[UINavigationController alloc]initWithRootViewController:uptvc];

当我的 UserProfileTableViewController 由于内存不足而被卸载时出现问题(可能是由于在我的应用程序中使用相机功能)。该页面将无法正确加载,因为它缺少从应用程序委托(delegate)(如上所示)传入的“userId”信息。我无法直接在 UserProfileTableViewController 中设置此 userId 信息(在 view did load 方法中),因为其他页面在将页面推送到其堆栈时可能会传递不同的 userId。

关于如何解决这个问题有什么建议吗?

最佳答案

首先,您应该将 UserProfileTableViewController 对象保留在应用程序委托(delegate)的 ivar 中(因为您在那里分配了它)。其次,让 app delegate 将该 userId 提供给 Controller 。第三,如果导航 Controller 从界面中移除/解除分配,那么即使内存不足,你的 uptvc 也不应该被解除分配。 View Controller 维护 Controller 的完整层次结构,即使内存不足,删除的是 View ,以及您告诉它们要删除的任何内容。

您当然也希望将 UINavigationController 保留在 AppDelegate 的 ivar 中。

关于objective-c - 如何处理由于内存不足导致页面卸载的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7624580/

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