1

I've been trying to get my UICollectionView to respond differently to single and double taps but all the answers I have found seem to suggest this is not really feasible because the single taps get recognised first. It works on really slow taps, but anything faster always initiates the default gesture recogniser (if anybody has got this to work I would love to know)...

So anyway, I have now resorted to putting buttons in my UICollectionViewCell (which has it's own class and NIB file).

The question is this:

What is considered the best way to use the button in the UIViewController of the collectionView?

I currently have a protocol in the header of my subclass of UICollectionViewCell and have declared my viewController as the delegate and implemented the required protocol functions.

In collectionView:cellForItemAtIndexPath: I set the VC as the delegate of the cell.

It all works but it seems a bit long-winded, and maybe not a great way of doing this.

The other way I was thinking of was instead of using delegates to simply call addTarget:Action: on the property of the UICollectionViewCell in collectionView:cellForItemAtIndexPath:.

This seems simpler but the delegate pattern looks to me like the better fit.

Any and all advice on which would be better, why, and any more appropriate alternatives welcomed!

Thanks.

4

2 回答 2

2

您使用委托模式的想法是正确的。视图的任何操作的最终责任对象是显示这些视图的视图控制器。因此,将它用作您单元协议的代表是正确的。

于 2013-06-18T12:25:51.573 回答
-1

创建一个自定义子视图UICollectionViewCell并将您的按钮放在initWithFrame方法中。将按钮声明为公共的,以便您以后可以在您的uicollectionviewcontroller或以uicollectionview编程方式创建时使用它。

于 2013-06-18T12:00:51.880 回答