您的位置:首页 > 产品设计 > UI/UE

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

2015-09-19 22:50 495 查看
点击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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: