从UICollectionReusableView查询到ImagePicker

时间:2016-05-19 01:42:28

标签: swift delegates uicollectionview protocols uicollectionreusableview

我的UICollectionReusableView有一个类,但我需要在该视图中使用一个按钮来执行从UICollectionView到imagePicker的segue。我试图使用一个委托,但我继续为代表获取nil。

protocol ShouldSegueToImagePickerDelegate{
    func shouldSegue()
}

class ProfileHeaderCollectionReusableView: UICollectionReusableView{

   var delegate: ShouldSegueToImagePickerDelegate!

   @IBAction func pressedChangeBGPicButton(sender: AnyObject) {
        delegate.shouldSegue()
    }


class ProfileCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout, ShouldSegueToImagePickerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate{

  var imagePicker = UIImagePickerController()

  func shouldSegue() {
      imagePicker.allowsEditing = false
       imagePicker.sourceType = .PhotoLibrary
       self.presentViewController(imagePicker, animated: true, completion: nil)
   }

  func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        imagePicker.dismissViewControllerAnimated(true, completion: nil)
    }

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

0 个答案:

没有答案