使用什么来代替已弃用的 UIImagePickerControllerDelegate 方法?
我遵循了一个很棒的教程(http://iphone.zcentric.com/ 2008/08/28/using-a-uiimagepickercontroller/) 使用 UIImagePickerController 从 iPhone 上的相册或相机获取图像。 问题是,该教程有点过时,并且文档引用了委托使用的方法,该方法自 3.0 起已被弃用。 问题是,文档未能提供有关使用什么的线索? 不推荐使用的方法是:
– imagePickerController:didFinishPickingImage:editingInfo:
上述方法的使用方式如下:
- (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)img editingInfo:(NSDictionary*)editInfo
{
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
问题:当前使用什么来代替不推荐使用的方法?
I followed a great tutorial (http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/) on using a UIImagePickerController to get images from the Photo Album or Camera on the iPhone. The problem is, the tutorial is a bit dated and documentation cites a method used by the delegate as being depreciated since 3.0. The problem is, the documentation failed to provide clues as to what to use in place? The deprecated method is:
– imagePickerController:didFinishPickingImage:editingInfo:
The above method is used as follows:
- (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)img editingInfo:(NSDictionary*)editInfo
{
image.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
QUESTION: What is currently used in place of the deprecated method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,以下是如何使用新的图像选择器 API。
首先,您需要一个这样声明的类,因为它将自身设置为图像选择器委托:
调出图像选择器的方法将如下所示。 它在此处声明为 IBAction,因此您可以将其直接连接到 Interface Builder 中的控件(如按钮)。 它还会进行检查,以便如果您使用 iPhone,它会调出相机界面,但在 iPod Touch 上,它会调出图库选择器:
那么您需要这两种方法:
Here's how to use the new image picker API in a nutshell.
First, you need a class declared like this since it's setting itself as the image picker delegate:
The method that brings up the image picker would go something like this. It's declared here as an
IBAction
so you can directly wire it to a control (like a button) in Interface Builder. It also checks so that if you're on an iPhone it brings up the camera interface but on an iPod Touch it brings up the gallery picker:Then you need these two methods:
引用苹果文档:
Quoting the Apple documentation: