第一个视图控制器具有多个文本字段以及三个按钮,其中每个按钮被推送到不同的视图控制器。其他视图控制器的情况也是如此。我想保持输入的文本字段值保持不变,无论在所有视图中从一个视图控制器导航到其他视图控制器吗?
2 回答
Be careful. You have to know when your controllers are deallocated. After deallocation you cannot restore the values, but if you stored the values in i.e. in NSUserDefaults, when the controller deallocates, then you can restore.
Normally, if another viewController is pushed, the last one is hold in memory, to get back smoothly. Forward pushing is always initializing a new controller, for which you have to think about how to store the old values (i.e. NSUserDefaults or implementing nscoding)
将按钮(或包含文本的 NSStrings)作为 ivars(实例变量)存储在您的第一个控制器中。只要您不摆脱该控制器并重新创建它,它们就应该持续存在。