- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的应用程序中,我必须存储一些数据,为此我使用了 NSHomeDirectory
并将数据与文档文件夹一起存储到其中。即
NSString *filename = [[[URL1 路径] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *Path=[NSHomeDirectory() stringByAppendingString:@"/Documents/"];
result=[Path stringByAppendingString:filename];
现在我想将这些数据显示到 UITableView 中,怎么可能我对此进行了搜索并了解了NSDocumentDirectory
.. NSHomeDirectory 与此有何不同? 我得到了这个答案
-(void)setUpTheFileNamesToBeListed{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [filePathsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Insert this line to add the file name to the list
cell.textLabel.text = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:indexPath.row]];
}
这就是我得到的..但是它如何为我工作......对于 NSHomeDirectory。
最佳答案
修改上面的代码
-(void)setUpTheFileNamesToBeListed{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
对此
-(void)setUpTheFileNamesToBeListed{
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingString:@"/Documents/"];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
关于iphone - 在 UITableView 中显示 NSHomeDirectory() 保存的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138130/
如何删除保存在 NSHomeDirectory 中的所有照片?它们是照片,保存在格式如下的路径中“/var/mobile/Applications/3EEDBD68-5496-458D-9EF0-06
我可以验证 NSHomeDirectory 中的“Documents”文件夹中是否至少有 1 个文件吗? NSError *error; NSFileManager *fileMgr = [NSFil
我正在查看 iOS 守护进程(预安装)的反汇编代码,我发现它使用了 NSHomeDirectory()。 我想知道 NSHomeDirectory() 是干什么用的?存储二进制文件的目录?或 / 或其
在我的应用程序中,我以这种方式将一些图像存储在 NSHomeDirectory 中: NSString *jpgPath = [NSHomeDirectory() stringByAppending
我有代码在 NSHomeDirectory 下创建一个文件夹,但它总是失败,我不明白为什么。它应该可以工作,但它一直说不允许该操作。有什么想法吗? NSURL *homeURL = [NSURL fi
我想了解两个常用的,NSDocumentDirectory,我在NSSearchPathForDirectoriesInDomains中用过。另一个是 NSHomeDirectory。这两者有什么区别
在单元测试中使用 NSHomeDirectory() 时,我得到: /Users/hgpc/Library/Application Support/iPhone Simulator/5.0 我期望当前
我刚刚将我的 Mac 应用程序沙箱化,并在我的应用程序中将图像保存在文档文件夹中。我有这个文件 URL:file:///Users/myUser/Documents/myApp/Images/logo
我遇到了一个问题 我从 CoreData 实体创建 JSON 数据。 // name : String // index : String // image : NSData var asJson :
所以,我目前通过这种方法将图像保存在我的 UIImageView 中: - (void)applicationDidEnterBackground:(UIApplication*)applicatio
在我的应用程序中,我必须存储一些数据,为此我使用了 NSHomeDirectory 并将数据与文档文件夹一起存储到其中。即 NSString *filename = [[[URL1 路径] lastP
我有一个 C 库,我正在尽可能少地修改它,以添加一个功能并使其在 iOS 上正常运行。它在 iOS 5.1 上运行良好,但在 iOS 6 上中断,因为它需要写入一个小的临时文件,而且我认为它曾经写入的
我注意到每次我用 Xcode 重新启动应用程序时,NSHomeDirectory 都会返回不同的路径,显然即使我手动单击该图标也是如此,因为它不会加载文件的内容。令我惊讶的是,每次我重新启动应用程序时
我是一名优秀的程序员,十分优秀!