我的 UICollectionReusableView 有一个类,但我需要该视图中的一个按钮来执行从 UICollectionView 到 imagePicker 的 segue。我曾尝试使用委托,但我不断为委托获得零。
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)
}