使用plist

-(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];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值