任何人请回答我,如何写入位于我的资源文件夹中的plist文件。请为我写一个示例代码。
答案 0 :(得分:6)
你做不到。应用程序包在iPhone OS设备上无法写入。
答案 1 :(得分:1)
-(IBAction)textFieldCheck:(id) sender {
myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6]retain];
NSArray *keys = [NSArray arrayWithObjects:@"Date",@"Time",@"Address",@"City",@"State",@"Zipcode",nil];
[myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
[NSString stringWithFormat:@"%@",txtDate.text],
[NSString stringWithFormat:@"%@",txtTime.text],
[NSString stringWithFormat:@"%@",txtAddress.text],
[NSString stringWithFormat:@"%@",txtCity.text],
[NSString stringWithFormat:@"%@",txtState.text],
[NSString stringWithFormat:@"%@",txtZip.text],nil]forKeys:keys]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"myPrimaryinfo.plist"];
[myPrimaryinfo writeToFile:path atomically:NO];
NSLog(@"PrimaryInfo array: %@", myPrimaryinfo);
}