HI 你可以给我发送示例代码,将数据添加到.plist中。 .my plist的格式如下。请帮助我
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>http://localhost:8888/sample</string>
<string>http://localhost:8888/sample</string>
</array>
</plist>
我将从实现代码中发送url字符串。请在此帮助我...
-(IBAction)AddFieldid)sender;
{
NSMutableArray *myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6]retain];
NSArray *keys = [NSArray arrayWithObjects:@"string",nil];
[myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
[NSString stringWithFormat:@"sample"],nil]forKeys:keys]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"urls.plist"];
[myPrimaryinfo writeToFile:path atomically:NO];
NSLog(@"PrimaryInfo array: %@", myPrimaryinfo);
}
由于
答案 0 :(得分:1)
我想这样的东西会起作用(不太适合iphone的东西):
// Loading
NSString *path = ...
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
// Manipulating
NSObject *newElement = ...
[array addObject:newElement];
// Storing
[array writeToFile:path atomically:YES];
按“ALT”+双击类名会打开此类的文档以及方法列表等。看看那里!