我正在約會應用程序。如你所知,用戶需要在約會應用程序中註冊多張圖片。如何在iOS中使用多個圖像選擇器與swift
所以我得到了如何在一個視圖中使用1個圖像選擇器。
但我不知道如何添加多個圖像選擇器。
我知道我只可以只用一個
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
}
和
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
picker.dismissViewControllerAnimated(false, completion:nil)
}
,所以我不能找到多個imagepicker View解決方案。
我的失敗代碼如下。
import UIKit
class 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)
}
@IBOutlet var picture1: UIImageView!
@IBOutlet var picture2: UIImageView!
func imagePickerController(picker1: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker1.dismissViewControllerAnimated(false, completion : nil)
self.picture1.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerController(picker2: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker2.dismissViewControllerAnimated(false, completion : nil)
self.picture2.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerControllerDidCancel(picker1: UIImagePickerController) {
picker1.dismissViewControllerAnimated(false, completion:nil)
}
func imagePickerControllerDidCancel(picker2: UIImagePickerController) {
picker2.dismissViewControllerAnimated(false, completion:nil)
}
}
你可以在這裏找到一個偉大的答案:http://stackoverflow.com/questions/20756899/how-to-select-multiple-images-from-uiimagepickercontroller 我遇到了你同樣的情況,發現好在這裏回答。 – truongky