私は、アプリケーションが終了したときにUITextFieldの内容をファイルに保存する簡単な方法を試しています。アプリケーションが再起動したときにUITextFieldを再ロードする際の問題
次のように私のヘッダファイルがある:
#define kFileName @"file.plist"
@interface applicationLaunchViewController : UIViewController {
UITextField *text1;
}
@property (nonatomic, retain) IBOutlet UITextField *text1;
-(void)applicationSaveFile:(NSNotification *)notification;
-(NSString *)dataFilePath;
私の実装ファイル:
@implementation applicationLaunchViewController
@synthesize text1;
-(void)applicationSaveFile:(NSNotification *)notification {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:text1.text];
[array writeToFile:[self dataFilePath] atomically:YES];
[array release];
}
-(NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDictionary = [paths objectAtIndex:0];
return [documentsDictionary stringByAppendingPathComponent:kFileName];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
self.text1.text = [array objectAtIndex:0];
[array release];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationSaveFile:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[super viewDidLoad];
}
は私が欠けている、このコード内の何かがありますか?私はアプリを起動するとき、それは正常に動作し、エラーは発生しません。私はまだOKアプリを閉じますが、私はマルチタスクでアプリケーションを閉じて、私はSIGKILLメッセージを取得する再オープンに行く。
ご協力いただければ幸いです。
あなたの質問のタイトルをさらに詳しく記述してください。 "私は間違って何をしていますか?"どんな種類の質問でもあります。 – Sebastian