在我看來,我有三個4個按鈕。當你點擊一個按鈕時,它會彈出UIPickerView,以便你可以從庫中選擇一個圖像作爲配置文件圖像。但是,當調用didFinishPickingMediaWithInfo時,它會一直存儲同一按鈕的不同照片。 單擊按鈕1,選擇圖像,從按鈕1設置圖像 單擊按鈕2,選擇圖像,再次設置按鈕1的圖像,而不是按鈕2。 與所有4個按鈕相同的東西。保持爲第一個按鈕設置圖像。設置多個按鈕來自UIImagePicker的圖像
func promptForCamera() {
let controller = UIImagePickerController()
controller.sourceType = UIImagePickerControllerSourceType.Camera
controller.delegate = self
self.presentViewController(controller, animated: true, completion: nil)
}
func promptForPhotoRoll() {
let controller = UIImagePickerController()
controller.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
controller.delegate = self
self.presentViewController(controller, animated: true, completion: nil)
}
func promptForSource() {
let actionSheet = UIActionSheet(title: "Image Source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Camera", "Photo Roll")
actionSheet.showInView(view)
}
func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int) {
if buttonIndex != actionSheet.firstOtherButtonIndex{
if buttonIndex != actionSheet.firstOtherButtonIndex{
promptForCamera()
}
else{
promptForPhotoRoll()
}
}
}
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
dismissViewControllerAnimated(true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {
let image = info[UIImagePickerControllerOriginalImage] as UIImage
self.p1Image = image
self.dismissViewControllerAnimated(true , completion: nil)
p1ImageButton.setImage(self.p1Image, forState: UIControlState.Normal)
}
@IBAction func p1PhotoTapped(sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){
promptForSource()
}
else{
promptForPhotoRoll()
}
}
很明顯,我知道在這個didFinishPickingMedia功能我設置p1ImageButton圖像。但是,我如何改變這個功能,以便爲拾取的相關按鈕設置圖像?我是否需要4種不同的didFinishPickingWithMedia功能(甚至有可能)?每次選取按鈕時,都會調用didFinish方法。我需要傳遞某種參數嗎?希望這一切都有道理。
交配感謝您的建議。看到我編輯的初始文章。我發佈了點擊圖片,檢查相機,選擇是要拍照還是從圖書館中選擇一張照片的整個過程。如果我使用這個系統,我沒有看到如何我可以定義我的4個不同的pickerControllers與這個過程。我錯過了什麼嗎? – candidaMan 2014-09-06 00:44:22