iPhone如何保存视图状态 [英] iPhone How To Save View States

查看:88
本文介绍了iPhone如何保存视图状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经开发了大约3个月的iphone应用程序,还有一些让我感到困惑的事情,我真的不知道如何绕过它们。

I have been developing iphone applications for around 3months now and theres a few things that stump me and i don't really have an idea how to work round them.

我有一个导航控制器控制我的应用程序中的视图,但是每个加载,使用然后推回的屏幕丢失所有信息,因为它似乎被重新实例化......我相信这是一个可能的内存管理问题?

I have a navigation controller controlling the views in my application however every screen that is loaded, used then pushed back loses all the information as it seems to be reinstantiated... I believe this is a possible memory management issue?

但是如何创建一个应用程序,在应用程序关闭之前导航并保留其视图中的所有信息。

But how to i create an app that navigates and retains all information in its views until the application is closed.

谢谢: )

推荐答案

可能你没有保留对视图控制器的引用,问题是 UIVIewController 不发布。

Possible you didn't keep a reference to the view controller, the issue is for UIVIewController not to be released.

使视图控制器成为一个ivar,当你将它推到堆栈上时,你只会实例化一次。

Make the view controller an ivar you will instanciate only one time when you push it on stack.

// in .h
MyViewController *mVC;

// in .m
// maybe when the user selects a row in a tableview
if(mVC == nil) {
    // first time use, alloc/init
    mVC = [[MyViewController ....];
}
// then push on the stack
[self.navigationController ....];

当然不要忘记稍后发布。

Of course don't forget to release it later.

这篇关于iPhone如何保存视图状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆