UINavigationController - 后退按钮导致数据损坏
我的应用程序使用 UINavigation 控制器,最终向用户显示数字数据。
问题是,只有用户直接进入计算屏幕而不点击后退按钮,计算才会正确。如果在任何时候按下后退按钮,即使在执行计算之后,某些值也会被损坏。
例如,第一次运行,使用正确的值:
2011-06-17 23:52:16.644 BlahBlah [19690:207] A = 146.000000 and B = 6.000000
如果在程序期间的任何时候按下后退按钮,则结果:
2011-06-17 23:54:05.888 BlahBlah [19690:207] A = 146.000000 and B = 4.012038
即使在后续重新计算中,这些值也将保持损坏状态,并且只有在程序完全重新启动时才会消失(即我必须在 Xcode 中再次构建并运行)。
我通常用脚本语言编写,因此我认为这是一个内存管理问题,因为我缺乏 Obj C 的经验。不过,我已经仔细研究了代码,确保每个 alloc/new 都有一个释放等我已经运行了调试器,它没有告诉我这部分代码。我现在完全陷入困境。
我的问题 - 我做错了什么,如何解决这个问题?
任何帮助表示赞赏。
更多信息 - 这就是我传递变量的方式。 myProfile 是一个具有属性 A 和 B 的对象的实例,这两个属性都是双精度型。
CalculateView *CalculateView = [[CalculateView alloc] initWithNibName:@"Calculate" bundle:nil];
CalculateView.myProfile = myProfile;
[self.navigationController pushViewController:CalculateView animated:YES];
我还应该提到 A 和 B 的值是从 plist 加载的。
My application, which employs a UINavigation controller, ends by displaying numeric data to the user.
The problem is that the calculations will only be correct if the user advances directly to the calculation screen without hitting the back button. If the back button is hit at any point, even after the calculations have been performed, some of the values will be corrupted.
For instance, the first run, with correct values:
2011-06-17 23:52:16.644 BlahBlah [19690:207] A = 146.000000 and B = 6.000000
And the result if the back button has been hit at any point during the program:
2011-06-17 23:54:05.888 BlahBlah [19690:207] A = 146.000000 and B = 4.012038
The values will remain corrupted even on subsequent recalculations, and will only go away if the program is completely restarted (ie. I have to hit build and run again in Xcode).
I usually write in scripting languages, and so I assumed that this was a memory management issue, owing to my lack of experience with Obj C. I've pored over the code, however, ensuring that every alloc/new has a release, etc. I've run the debugger, which has nothing to tell me about this part of the code. I'm completely stuck at this point.
My question - what am I doing wrong, and how can I fix this issue?
Any assistance appreciated.
Further information - this is how I am passing variables around. myProfile is an instance of an object with attributes A and B, which are doubles.
CalculateView *CalculateView = [[CalculateView alloc] initWithNibName:@"Calculate" bundle:nil];
CalculateView.myProfile = myProfile;
[self.navigationController pushViewController:CalculateView animated:YES];
I should also mention that the values for A and B are loaded from a plist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应该是这样的
It should be like this