【问题标题】:What are the methods/classes I need to create an iPhone upload photo form?创建 iPhone 上传照片表单需要哪些方法/类?
【发布时间】:2012-01-19 09:19:44
【问题描述】:

目前我有一个带有 ImageViewer 和 2 个按钮(浏览和上传)的视图。我目前正在寻找按下按钮后显示 iPhone 相册的方法。

我在这里看过这个例子,但我认为这是你想将照片上传到服务器时调用的方法。

Objective C: How to upload image and text using HTTP POST?

我想复制网络上传表单的功能。 1. 点击 按钮浏览文件夹。 2.选择照片并在容器中显示。 3. 点击上传,上传照片到服务器。

**更新: 找到了一些很好的教程,帮助我开始使用我的 iPhone 应用照片上传表单。

使用 UIImagePickerController

http://iosdevelopertips.com/camera/camera-application-to-take-pictures-and-save-images-to-photo-album.html

http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/

Adding images to iPhone Simulator

【问题讨论】:

  • 你想看UIImagePickerController

标签: iphone objective-c uiimageview


【解决方案1】:

您必须使用UIImagePickerController
这是UIImagePickerController的类参考

在您的按钮事件处理程序方法中初始化选择器控制器。
然后将 UIImagePickerControllerDelegate 设置为您当前的 viewController
这是UIImagePickerControllerDelegate 的类参考

picker.delegate = self;

将选择器的UIImagePickerControllerSourceType设置为UIImagePickerControllerSourceTypePhotoLibrary

picker.UIImagePickerControllerSourceType = UIImagePickerControllerSourceTypePhotoLibrary

然后展示pickerViewController(如果您的目标设备是iPad,则在popOver控件中展示imagePickerView)
一旦用户选择了一个图像选择器控制器将自动调用它的委托方法

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

您可以通过从NSDictionary *info 访问UIImagePickerControllerOriginalImage 的值来获取所选图像

然后您可以使用帖子link中提到的图像上传到服务器

这些是 UIImagePickerController 的一些教程 Tutorial one
Tutorial two
Tutorial three

【讨论】:

  • 我只看到一个空白视图,顶部有 2 个蓝色水平条。 UIImagePickerController *imgP = [[UIImagePickerController alloc] init]; imgP.delegate = self; imgP.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self.view addSubview:imgP.view]; [imgP release];
  • 我以编程方式将其添加到 loadView 的 uiviewcontroller 中
  • 好的修复了,呵呵,我不需要为它创建一个新的视图。只是打电话给[self presentModalViewController:picker animated:YES];。 :)
  • 好到这里,我已经提到你必须展示一个pickerView([self presentModelView...)
【解决方案2】:

要从 iPhone 库中获取图像,您必须使用 UIImagePickerController

m_imagePickerController = [[UIImagePickerController alloc] init];
m_imagePickerController.delegate = self;
m_imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2012-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 2016-11-27
    • 2016-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多