-(NSString *)dataFilePath//用来返回数据文件的完整路径名
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *paths = [path objectAtIndex:0];
return [paths stringByAppendingPathComponent:kFileName];
}
-(void)applicationWillTerminate:(NSNotification *)notification//应用程序在退出时调用,将数据保存到数据列表
{
NSMutableArray *array = [[
NSMutableArray alloc]init];
[array addObject:[text_id text]];
[array addObject:[text_password text]];
[array writeToFile:[self dataFilePath] atomically:YES];
//[array release];
}
-(void)viewDidLoad
{
NSString *filePath = [self dataFilePath];//得到文件路径
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])//如果该文件存在就加载
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
[text_id setText:[array objectAtIndex:0]];
[text_password setText:[array objectAtIndex:1]]; //[array release];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}
{
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *paths = [path objectAtIndex:0];
return [paths stringByAppendingPathComponent:kFileName];
}
-(void)applicationWillTerminate:(NSNotification *)notification//应用程序在退出时调用,将数据保存到数据列表
{
NSMutableArray *array = [[
NSMutableArray alloc]init];
[array addObject:[text_id text]];
[array addObject:[text_password text]];
[array writeToFile:[self dataFilePath] atomically:YES];
//[array release];
}
-(void)viewDidLoad
{
NSString *filePath = [self dataFilePath];//得到文件路径
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])//如果该文件存在就加载
{
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
[text_id setText:[array objectAtIndex:0]];
[text_password setText:[array objectAtIndex:1]]; //[array release];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:app];
[super viewDidLoad];
}