ios - 如何添加多个 ImageView 并且每个 ImageView 都可以做图像选择器?

标签 ios swift image

enter image description here我正在制作约会应用程序。 因此用户需要更新他们的个人资料中的图像。 在个人资料部分, 有小 3 个 ImageView 。 如果他们想将图像添加到每个 ImageView 中, 他们应该通过 UIimagepicker 更新每个 ImageView 。 但我知道我只能使用 UIImagepikerControllerDelegate 协议(protocol)中的一个函数。

我该怎么做?

下面是我失败的代码

导入UIKit

类RegisterPicture:UIViewController、UIImagePickerControllerDelegate、UINavigationControllerDelegate {

@IBAction func pick1(sender: AnyObject) {

    let picker1 = UIImagePickerController()

    picker1.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

    picker1.allowsEditing = true

    picker1.delegate = self

    self.presentViewController(picker1, animated: false, completion: nil)
}

@IBAction func pick2(sender: AnyObject) {

    let picker2 = UIImagePickerController()

    picker2.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

    picker2.allowsEditing = true

    picker2.delegate = self

    self.presentViewController(picker2, animated: false, completion: nil)
}

@IBAction func pick3(sender: AnyObject) {

    let picker = UIImagePickerController()

    picker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum

    picker.allowsEditing = true

    picker.delegate = self

    self.presentViewController(picker, animated: false, completion: nil)
}

@IBOutlet var picture1: UIImageView!

@IBOutlet var picture2: UIImageView!

@IBOutlet var picture3: UIImageView!

func imagePickerController(picker1: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    picker1.dismissViewControllerAnimated(false, completion : nil)


}

func imagePickerController(picker2: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    picker2.dismissViewControllerAnimated(false, completion : nil)
    self.picture2.image = info[UIImagePickerControllerOriginalImage] as? UIImage

}

func imagePickerController(picker3: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

    picker3.dismissViewControllerAnimated(false, completion : nil)
    self.picture3.image = info[UIImagePickerControllerOriginalImage] as? UIImage

}

func imagePickerControllerDidCancel(picker: UIImagePickerController) {

    picker.dismissViewControllerAnimated(false, completion:nil)

}

func imagePickerControllerDidCancel(picker2: UIImagePickerController) {

    picker2.dismissViewControllerAnimated(false, completion:nil)

}

func imagePickerControllerDidCancel(picker3: UIImagePickerController) {

    picker3.dismissViewControllerAnimated(false, completion:nil)

}

最佳答案

不确定我是否理解您的需要,但我建议这些 UIImageView 可以位于 Collection View 中。

通过这样做,图像选择器的唯一委托(delegate)将是保存图像 Collection View 的 View Controller ,您只需使用所选图像更新所选单元格

关于ios - 如何添加多个 ImageView 并且每个 ImageView 都可以做图像选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37205196/

相关文章:

java - 如何将图像从MYSQL显示到JTable单元格行?

html - 如何将 <img> 放在背景图片后面

ios - 渐变颜色不适用于 SWReveal View Controller 内容 View

iOS 10 推送通知 - willPresentNotification 和 didReceiveNotificationResponse 是如何工作的?

ios - 自定义单元格类中的 Indexpath.row

ios - 如何以较低的分辨率渲染 SceneKit 着色器?

ios - 快速组合 : Unable to infer complex closure return type error

ios - UISearchController 的 UISearchBar 在事件时移出屏幕

ios - 在 iPhone 中隐藏状态栏,但在 iPad 中没有

html - 使用 HTML <img> 标签作为背景图片而不是 CSS background-image 属性?