iOs:我什么时候应该从视图初始化即将到来的控制器(UIImagePickerController)?
假设我有一个导航控制器,下一个操作是拍照或从库中选择图像。
如果我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会在第一次调用控制器时延迟加载控制器(在 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.
看来在您的情况下,您总是需要
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.