没有调用imagePickerController委托,Swift

时间:2015-11-19 05:48:14

标签: ios swift parse-platform

我有一张个人资料图片,也可以作为一个按钮,当用户点击图片选择器显示的图片时,他们可以选择他们想要用作个人资料图片的图片,但SELECT m.username FROM members m, (SELECT sponsor, COUNT(sponsor) FROM members GROUP BY sponsor HAVING COUNT(sponsor) >= 5) c WHERE m.username != c.sponsor 不是被调用,并且没有调用Parse db映像文件。为什么会发生这种情况,我该如何解决?

imagePickerController

1 个答案:

答案 0 :(得分:4)

swift 2.0及以后,如果您使用任何代理UIImagePickerControllerDelegate,则需要强制实现委托方法,否则不要在您的viewcontroller中使用或不添加,这是概念,现在按照这个 一些例子

<强>步骤1

在视图控制器中添加UIImagePickerControllerDelegate, UINavigationControllerDelegate

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet var imageView: UIImageView!

let imagePicker = UIImagePickerController()

<强>步骤-2

  override func viewDidLoad() {
super.viewDidLoad()

imagePicker.delegate = self // Its Manotary
}

<强>步骤-3

 // Present the Image picker controller

@IBAction func loadImageButtonTapped(sender: UIButton) {
imagePicker.allowsEditing = false
imagePicker.sourceType = .PhotoLibrary

presentViewController(imagePicker, animated: true, completion: nil)
}

<强>步骤4

// call the delegate method for pick the image

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
    imageView.contentMode = .ScaleAspectFit
    imageView.image = pickedImage
}

dismissViewControllerAnimated(true, completion: nil)
}

<强>步骤5

// finally dismiss the Imagepicker controller

func imagePickerControllerDidCancel(picker: UIImagePickerController)    {
dismissViewControllerAnimated(true, completion: nil)
}