你能给我一些算法或例子吗?
答案 0 :(得分:1)
NSUserDefaults
很好地保留了数据片段。
示例:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview:tabBarController.view];
if ([[NSUserDefaults standardUserDefaults] integerForKey:kTabIndexKey])
tabBarController.selectedIndex = [[NSUserDefaults standardUserDefaults] integerForKey:kTabIndexKey];
}
- (void)applicationWillTerminate:(UIApplication *)application {
[[NSUserDefaults standardUserDefaults] setInteger:tabBarController.selectedIndex forKey:kTabIndexKey];
}
持久并加载一个整数(您的方法将是“setString”和“stringForKey”,请检查文档。)