iOs:我什么时候应该从视图初始化即将到来的控制器(UIImagePickerController)?

发布于 2024-10-02 04:07:16 字数 340 浏览 0 评论 0原文

假设我有一个导航控制器,下一个操作是拍照或从库中选择图像。

如果我在 didSelectRowAtIndexPath: 期间初始化 UIImagePickerController,(我相信)响应会慢一些,因为控制器需要初始化。此外,如果用户取消并再次打开,它每次都会重新实例化该控制器。

但是,如果我在导航控制器的 viewDidLoad: 期间创建控制器,则当用户位于该视图上时它会占用内存。附带问题:但这会减慢导航的加载时间吗?

或者应该在加载视图时在 NSOperation 中完成?

总的来说,加载 ImagePicker 的最佳位置是什么?

Suppose I have a navigation controller where the next action is to take a picture or select an image from the library.

If I initialize UIImagePickerController during didSelectRowAtIndexPath:, (I believe) the response will be a little slower as the controller needs to initialized. Also, if the user cancels and opens again, it would reinstantiate that controller every time.

However, if I create the controller during viewDidLoad: of the navigation controller, it takes up memory while the user is on that view. Side questions: Does this, however, slow down the loading time of the navigation?

Or should it be done in an NSOperation when the view is loaded?

Overall, what would be the best place to load the ImagePicker?

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

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

发布评论

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

评论(2

财迷小姐 2024-10-09 04:07:16

我会在第一次调用控制器时延迟加载控制器(在 didSelectRowAtIndexPath 中),这样就不必每次都重新加载,也不用担心初始化时间。

I'd lazy load the controller when it first gets called (in didSelectRowAtIndexPath) so it wouldn't have to be reloaded every time, and not worry about initialization time.

时光与爱终年不遇 2024-10-09 04:07:16

看来在您的情况下,您总是需要 didSelectRowAtIndexPath 上的图像选择器。您可以将其加载到视图上并进行自定义(相机、相机胶卷等)并显示在行选择上。也许这并不重要。无论如何,UIImagePickerController 的呈现速度非常慢,尤其是使用相机时。

我不建议使用 NSOperation 来完成此任务。

It seems that in your case you will always need an image picker on didSelectRowAtIndexPath. You can load it on the view and customize (camera, cameraroll, etc.) and present on the row selection. Probably it doesn't matter that much. UIImagePickerController presentation is very slow anyway, especially with the camera.

I don't recommend an NSOperation for this task.

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