UIProgressBar 加载 NSMutableDictionary

发布于 2024-07-27 16:55:52 字数 94 浏览 2 评论 0原文

我的程序正在加载一个相当大的 MutableDictionray,我想使用 UIProgressBar。 有人建议如何确定加载时间以使其工作吗?

谢谢

I'm my program i'm loading a fairly large MutableDictionray and I would like to use a UIProgressBar. Does anyone have a suggestion of how to determine the loading time to make this work?

Thanks

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

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

发布评论

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

评论(1

假装爱人 2024-08-03 16:55:52

我相信您不会找到简单的答案,但这里有一些提示。 我假设您当前正在使用 -dictionaryWithContentsOfFile: 加载此内容。

  • 首先,不要强迫用户等待长时间加载,而是考虑更改数据存储。 与非常大的字典相比,核心数据可能是更好的工具。

  • 使用 -[NSFileHandle readDataOfLength:] 将文件读入 NSData 中,以便对其进行分块,以便您可以更新进度条。 您可以在后台线程上执行此操作并发布通知,或者在主线程上调用委托方法以使进度指示器更新。

  • 您可能想尝试使用-readInBackgroundAndNotify。 我不知道 iPhone 的缓冲区大小,但它可能足够小,可以以合理的时间间隔获取通知,并且它应该消除管理您自己的后台线程的需要。

  • 将数据读入 NSData 后,使用 +[NSPropertyListSerialization propertyListFromData:mutabilityOption:format:errorDescription: 对其进行解析。 希望这应该足够快,不会挂起任何东西,但如果太慢,您可以在后台线程上执行此操作,并将其作为上次进度条更新的一部分。 可能需要进行一些实验才能使 UI 平滑。

I don't believe you'll find an easy answer to this, but here are some pointers. I assume you're currently loading this with -dictionaryWithContentsOfFile:.

  • First, rather that forcing the user to wait for a long load, consider changing your data storage. Core Data may be a better tool for this than a very large Dictionary.

  • Read the file into an NSData using -[NSFileHandle readDataOfLength:] in order to chunk it so you can update your progress bar. You can do this on a background thread and post notifications or call a delegate method on the main thread to let the progress indicator update.

  • You may want to experiment with -readInBackgroundAndNotify. I don't know the buffer-size off the top of my head for the iPhone, but it may be small enough to get notifications back at reasonable intervals, and it should remove the need to manage your own background thread.

  • Once you've read the data into an NSData, parse it using +[NSPropertyListSerialization propertyListFromData:mutabilityOption:format:errorDescription:. This should hopefully be fast enough not to hang anything, but if it's too slow, you can do this on a background thread and make it part of your last progress bar update. Some experimentation may be required to get the UI smooth here.

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