从collectionView中获取标签号didSelectItemAtIndexPath - 目标C.

时间:2014-03-31 22:42:22

标签: ios objective-c

我正在尝试抓取我在collectionView didSelectItemAtIndexPath函数中点击的单元格的标记号。

这是我的代码:

标签设置:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
....
   cell.tag = [theID intValue]; //SET VIDEO ID
...
}

标签是必需的,因为它是我用来发送到我的服务器以获取信息的ID

我的选择器:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%@",[[collectionView viewWithTag:indexPath] class]);

}

我们的想法是根据cell's

选择indexPath代码

不确定我是如何做到这一点的。

建议吗?想法?

1 个答案:

答案 0 :(得分:3)

使用UICollectionView' s cellForItemAtIndexPath:,您可以获取单元格对象。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
    NSInteger tag = cell.tag;
    NSLog(@"%d",tag);
}
相关问题