关于如何解决这个问题的任何建议,或者更好的实现设计?
要求
我的实现理念
问题
我的分析
(a) 主页“viewDidLoad”实际上被调用了,这是我的概念没想到的,所以当我从详细 View (UINavigationController) 中点击 BACK 按钮转到主 View (RootViewController) 时,实际上我的代码运行并尝试将用户再次返回到详细信息页面
(b) 在此之后我在日志中注意到 [AppointmentListController viewDidLoad] 似乎在调用前一个 AppointmentListController dealloc 方法之前被调用(即就像我在 Controller A 中一样,回到 Controller B,但被抛回 A -并且第一部分的初始 dealloc 直到很晚才开始......)
问题
关于如何更好地实现我的要求的任何建议? (如何检查,将它们放入哪种方法)
代码
- (void)viewDidLoad {
[super viewDidLoad];
// My Implementation of the Requirements which seems flawed in the case there is memory warning triggered
if ( previousSelectedScreen >= 0 ) {
// Setup New Controller
AppointmentListController *appointmentListController = [[AppointmentListController alloc] initWithNibName:@"AppointmentListController" bundle:nil];
appointmentListController.screenToShow = previousSelectedScreen;
// Push new view onto stack
[[self navigationController] pushViewController:appointmentListController animated:NO];
[appointmentListController release];
}
}
最佳答案
这是我的建议:而不是在您的 View Controller 中使用此逻辑,而是在您的应用程序委托(delegate)中使用它。通过在显示之前构建导航堆栈,您有望避免导航栏等可能发生的一些奇怪的事情。为了摆脱内存警告,您可能需要查看您的应用程序如何分配内存:它可能不一定是与此有关。
无论如何 - 在您的应用程序委托(delegate)中,您可以执行检查以查看用户退出时是否在详细信息页面上。如果是,您可以创建一个包含导航堆栈的数组(即,主屏幕 -> 详细信息页面)。然后,您可以使用其 setViewControllers
方法将其传递给导航 Controller 。完成此操作后,您可以显示窗口并完成启动应用程序。
关于iphone - 如果用户以前在此页面上,我如何实现自动跳转到详细页面(或修复我的代码以执行此操作,但存在设计缺陷),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6242265/