存储到 plist 在模拟器上有效,但在设备上无效

发布于 2024-09-08 03:03:11 字数 422 浏览 2 评论 0原文

我目前将数据添加到 NSMutableArray,然后从中读回以填充 UITableview。这在模拟器上工作正常,但在设备上测试时却不起作用。该应用程序仍然从 plist 中读取,因此如果我手动向其中添加数据,应用程序会将其显示在表格视图中。但无法在应用程序上读取或写入它?

我使用当前的代码,

newTitle = [NSString stringWithFormat:@"%d_%@",[Daily_QuoteViewController counter], t];
[plistArray addObject:newTitle];
[plistArray writeToFile:filepath atomically: YES];

我读到列表也需要序列化,但其他人说这没有必要?

任何帮助表示赞赏。

谢谢

I currently add data to a NSMutableArray and then read back from it to populate a UITableview. This works fine on the simulator, but when testing on the device it doesnt work. The app still reads from the plist, so if I manually add data to it the app displays it in the tableview. But Cannot read or write to it on app ?

I use the current code

newTitle = [NSString stringWithFormat:@"%d_%@",[Daily_QuoteViewController counter], t];
[plistArray addObject:newTitle];
[plistArray writeToFile:filepath atomically: YES];

I have read that the list needs to be serialized as well, but others say this isnt necessary?

Any help is appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是我以为 2024-09-15 03:03:11

您确定您的应用程序对您尝试写入 plist 的位置具有写入权限吗?模拟器上的文件系统访问与实际设备上存在差异。

更新:您可以在 iPhone 应用程序编程指南:一些重要的应用程序目录。获取这些文件夹位置的标准方法在 iPhone 应用程序编程指南:获取应用程序目录的路径。以下是如何获取 Documents 文件夹并构建其中文件的路径的示例:

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                     NSDocumentDirectory,
                     NSUserDomainMask, YES
                 );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *urla = [NSURL fileURLWithPath:[documentsDirectory
                         stringByAppendingString:@"/myinfo.plist"]];

您将使用哪个应用程序文件夹取决于文件的实际内容和预期用途。

Are you sure your app has write permissions to the location you are trying to write the plist to? There are differences between the file system access on the simulator and the actual device.

Update: You can read more about the folders available for your app in iPhone Application Programming Guide: A Few Important Application Directories. The standard way of getting the locations of these folders is described in iPhone Application Programming Guide: Getting Paths to Application Directories. Here's an example how to get the Documents folder and construct a path to a file in it:

NSArray *paths = NSSearchPathForDirectoriesInDomains(
                     NSDocumentDirectory,
                     NSUserDomainMask, YES
                 );
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *urla = [NSURL fileURLWithPath:[documentsDirectory
                         stringByAppendingString:@"/myinfo.plist"]];

Which application folder you will use depends on the actual content of your file and the intended use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文