NSMutableArray
からのデータを保存するためにを使用していますが、データを だけでなくアプリケーションにもUITableView
保存したいと考えています。これまでのところ、これを行う方法は次のとおりです。NSUserDefaults
didEnterBackground
willTerminate
代理人:
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
EXViewController *main = [[EXViewController alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:main.data forKey:@"dataKey"];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
EXViewController *main = [[EXViewController alloc] init];
[[NSUserDefaults standardUserDefaults] setObject:main.data forKey:@"dataKey"];
}
main.data
ですNSMutableArray
。
しばらくテーブルビューを扱っていなかったので、これを行う方法を忘れました。どんな助けでも大歓迎です、ありがとう!
完全なデリゲート コード (.h):
#import <UIKit/UIKit.h>
@class EXViewController;
@interface EXAppDelegate : UIResponder <UIApplicationDelegate> {
EXViewController *_main;
NSString *title;
}
// Data to be added
@property (nonatomic, retain) NSString *title;
// Default properties
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) EXViewController *viewController;
@end
そしてM):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_main = [[EXViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[EXViewController alloc] initWithNibName:@"EXViewController" bundle:nil];
// Create navigation controller
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}