点击UICollectionViewCell上的UIButton如何获取当前的UICollectionViewCell?

来源:互联网 发布:java设计模式 编辑:程序博客网 时间:2024/06/06 03:12

点击UICollectionViewCell上的UIButton如何获取当前的UICollectionViewCell?

通常的做法是这个UIButton的superview,如果不是UICollectionViewCell,再继续superview,如果不是……。

不是你妹,这样的判断方法感觉很蠢。让我想到UITableViewCell。

不然,应该怎么做呢?可以看以下代码:

- (void)btnAction:(id)sender event:(id)event{    NSSet *touches = [event allTouches];    UITouch *touch = [touches anyObject];    CGPoint position = [touch locationInView:self.collectionView];    NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:position];    UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];}

这样就可以获取当前的UICollectionViewCell。

0 0
原创粉丝点击