使用选定的单元格indexPath,UICollectionView

时间:2013-06-07 07:47:41

标签: iphone ios6 uicollectionview

使用UICollectionView生成座位图。所以现在哪个单元格被选中,得到它indexPath但是如何使用选定单元格indexPath显示为行和座位号。  以下是我试过的方式。

int ind = indexPath.item;
    [array addObject:[NSString stringWithFormat:@"%d", ind]];

它提供如下输出。

"<NSIndexPath 0x12135500> 2 indexes [0, 1]"

如何访问此内容并仅获取值0,1。 请指导以上内容。

1 个答案:

答案 0 :(得分:2)

一旦看到这个,它会帮助你

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    int ind = indexPath.item;
    int section=indexPath.section;
    [arr addObject:[NSString stringWithFormat:@"%d",ind]];
    NSLog(@"%d,%d",section,ind);
}

编辑:

if([arr containsObject:[NSString stringWithFormat:@"%d",ind]]){
        [arr removeObject:[NSString stringWithFormat:@"%d",ind]];
    }

int n=[array indexOfObject:[NSString stringWithFormat:@"%d",ind]];
    if([n<[array count]]){
        [array removeObjectAtIndex:n];
    }
相关问题