如何获取文件路径?在基于文档的应用程序中加载文档 [英] How to get file path? Loading documents in Document based app
问题描述
我希望能够保存和加载文档,所以我正在尝试使用以下方法:
I want to be able to save and load documents, so I'm trying to use these methods:
[NSKeyedArchiver archiveRootObject:rootObject toFile:@"myMap.map"];
[NSKeyedArchiver archiveRootObject: rootObject toFile: @"myMap.map"];
rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:@"myMap.map"];
rootObject = [NSKeyedUnarchiver unarchiveObjectWithFile:@"myMap.map"];
我打算把什么作为文件参数?我现在只有一个常量字符串,但这意味着我只能加载一个文件,我假设有一种方法可以从打开的面板中获取用户的选择作为参数,但是如何呢?
What am I meant to put as the file argument? I just have a constant string for now, but that means I can only load one file, I assume there's a way to get the user's selection from the open panel to be the argument, but how?
推荐答案
使用NSFileManager:
Use NSFileManager:
NSArray *allFileNames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"SomeDirectory"];
这篇关于如何获取文件路径?在基于文档的应用程序中加载文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!