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

首先在AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法中初始话本地文件:[color=red]NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
NSLog(@"%@",path);
self.filename=[path stringByAppendingPathComponent:@"test.plist"];[/color]//test.plitst文件创建;


AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[color=red]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];//将数组中值保存到本地
[/color]

self.listdata = [NSKeyedUnarchiver unarchiveObjectWithFile:appDelegate.filename];//用listdata数组读取本地数据
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值