0
votes

I have a UICollectionViewCell subclass that is supposed to hold an image in a UIImageView. In the cell I have a UIScrollView that holds the UIImageView so the UIImageView can zoom.

The question I have is where do I put the UIScrollViewDelegate? Putting it in the UICollectionViewCell seems like it would break MVC. I can't make the cell a property of the UIViewController the UICollectionView is in because that would break cell reuse in dequeueReusableCellWithReuseIdentifier. Does it go in the cell subclass, and if so, what's the proper UIView method for the delegate methods to go in?

1

1 Answers

0
votes

Having the view subclass of your collection view cell conform to the UIScrollViewDelegate method does not break MVC and would be appropriate for handling scrolling events within the individual cells. The delegate methods don’t go into a method of UIView rather they are added to your subclass of UIView.

Think of the views as a hierarchy and as long as your delegate methods stay at the same level, there will be no conflicts with other levels. This illustrates the beauty of protocols in that functionality can be added to different layers within MVC without forming or requiring a tightly coupled relationship.