Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Plist文件路径错误?_Iphone_Xcode_File_Plist - Fatal编程技术网

Iphone Plist文件路径错误?

Iphone Plist文件路径错误?,iphone,xcode,file,plist,Iphone,Xcode,File,Plist,我正在尝试使用以下代码将包含文本的NSMutableArray保存到plist文件: - (IBAction)saveDoc:(id)sender { NSString *typedText = typingArea.text; NSMutableArray *totalFiles = [[NSMutableArray alloc] initWithObjects:typedText, nil]; NSLog(@"Created: %@", totalFiles); NSArray *paths

我正在尝试使用以下代码将包含文本的NSMutableArray保存到plist文件:

- (IBAction)saveDoc:(id)sender
{
NSString *typedText = typingArea.text;
NSMutableArray *totalFiles = [[NSMutableArray alloc] initWithObjects:typedText, nil];
NSLog(@"Created: %@", totalFiles);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"savedFiles.plist"];
NSLog(@"Found Path: %@", path);
//[totalFiles addObject:typedText];

[totalFiles writeToFile:path atomically:YES];
NSLog(@"File Written: %@  to: %@", totalFiles, path);
[totalFiles release];
NSLog(@"Released: %@", totalFiles);
}
所有NSLog都会按预期返回适当的值。我使用此代码包装一个新的NSMutableArray,其中包含plist的内容:

- (void)viewDidLoad {
file = [[NSBundle mainBundle] pathForResource:@"savedFiles" ofType:@"plist"];
NSLog(@"Got Path: %@", file);
array = [NSMutableArray arrayWithContentsOfFile:file];
NSLog(@"Loaded Array into new array: %@", array);





//UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"fdsfasdf" message:[dic objectForKey:@"item1"] delegate:self cancelButtonTitle:@"ldfghjfd" otherButtonTitles:nil] autorelease];
//[alert show];



[super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
//self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
此代码中的nslog返回的路径与第一个返回的路径略有不同。它还表示数组为(null)

如何从plist文件加载内容

提前感谢,


Tate

首先尝试初始化阵列:


array=[[NSMutableArray alloc]initWithContentsOfFile:file]

首先尝试初始化阵列:


array=[[NSMutableArray alloc]initWithContentsOfFile:file]

谢谢!Itt显示文件!现在如何让它显示多个文件?例如:如果用户创建一个文件然后保存它,它将显示在tableview中。然后,如果用户创建另一个文件并保存它,我希望它向tableview添加另一个单元格,而不是覆盖和替换旧的单元格,如果你知道我的意思的话。谢谢谢谢!Itt显示文件!现在如何让它显示多个文件?例如:如果用户创建一个文件然后保存它,它将显示在tableview中。然后,如果用户创建另一个文件并保存它,我希望它向tableview添加另一个单元格,而不是覆盖和替换旧的单元格,如果你知道我的意思的话。谢谢泰特