ios - 如何在主从 ios 应用程序中保存详细 View 的状态?

标签 ios iphone xcode ipad

我有一个主从应用程序,对于主视图中的每个单元格,我想要一个唯一的详细 View 。我想我可以做的是在退出 View 时保存详细 View 的状态,然后在选择不同的单元格时以某种方式访问​​该 View 的保存数据并将其显示在详细 View 中。详细 View 上唯一的对象类型是 TextView 和 ImageView 。我该怎么做呢?有没有更好的办法?

最佳答案

如果主细节 View 类似于设置页面,那么您可以将该数据保存在 NSUserDefaults

=> 设置值:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue: @"some_value" forKey: @"some_setting"];
[defaults synchronize];

=> 获取值:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.label1.text = [defaults stringForKey: @"some_setting"];

您可以使用如下所示的模型:

Model - A common class that remembers all the settings/configurations
Master VC - Do some changes and store those changes in the Model
Detail VC - Access the Model and display cells accordingly

关于ios - 如何在主从 ios 应用程序中保存详细 View 的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13595240/

相关文章:

ios - 谷歌地图iso瓦片层不起作用GMSTileURLConstructor GMSURLTileLayer

iphone - 如何修改普通 UITableView 中 'empty' 单元格的外观?

iphone - 在 Interface Builder 中添加背景图片

ios - Xcode 6上的Swift编译器错误

iphone - Core-Plot:Interface Builder 文件中存在未知类 CPLayerHostingView

javascript - Instruments Xcode 中的 UIAutomation 测试模块

ios - 使用 FFMPEG 将 RTSP 流录制到本地文件

ios - 用于 UIWebView 的 NSURLProtocol 缓慢下载的占位符图像

ios - 布局 : How to use property in visual format

iphone - 警告 : Supported orientations are not matched pairs (Info. plist)