当前位置:首页 > 开发 > 移动开发 > 正文

本地数据的写入(保存)和读取 plist

发表于: 2014-10-25   作者:caoyudong   来源:转载   浏览:
摘要: 首先在AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中初始话本地文件: NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocument
首先在AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中初始话本地文件: NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"%@",path);
    self.filename=[path stringByAppendingPathComponent:@"test.plist"];
//test.plitst文件创建;


AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    NSMutableArray *temp=[NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//先用数组读取本地数据

if (temp == nil) {
        temp = [[NSMutableArray alloc]initWithCapacity:0];//
    }
   
    NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:m_labelpeople.text,@"1",m_labelrestaurant.text,@"2",m_labelpackage.text,@"3",price,@"4", nil];
    [temp addObject:dic];//在数组中继续添加界面中label的值
[NSKeyedArchiver archiveRootObject:temp toFile:appDelegate.filename];//将数组中值保存到本地


self.listdata = [NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//用listdata数组读取本地数据
   

本地数据的写入(保存)和读取 plist

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号