如何找到标题部分号。在uitableview中的细胞?

时间:2016-08-20 09:36:06

标签: ios objective-c uitableview uicollectionview

我创建了uitableview,其中有节和单元格下拉。每个单元格都使用collectionview创建。

例如,当我点击"颜色"部分。 [这里我存储了节号。] UICollectionView单元格正在展开。我可以检查并取消选中这些单元格。

- (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{
     findSection = gestureRecognizer.view.tag;
  }

enter image description here

我的问题是,如果所有部分都是ON,当我直接将单元格轻击到任何部分时,我点击的最后一部分,这些单元格都会被更改。不是我拍过的细胞的当前部分。

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
     UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CollectionViewCellIdentifier forIndexPath:indexPath];
    cell.backgroundColor =[UIColor clearColor];

    nonChecked = [UIImage imageNamed:@"check"];
    checked = [UIImage imageNamed:@"check_active"];

    checkbox = [[UIImageView alloc]initWithFrame:CGRectMake(10, 9, 11, 11)];
    checkbox.tag = indexPath.row+100;
    UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myChecked:)];
    tapped.numberOfTapsRequired = 1;
    checkbox.userInteractionEnabled = YES;
    [checkbox addGestureRecognizer:tapped];
    [cell.contentView addSubview:checkbox];

    NSIndexPath * myIndexPath =  [NSIndexPath indexPathForRow:indexPath.row+100 inSection:findSection];

    NSString * result = [[SingletonClass shareSingleton].resultOfFilter member:myIndexPath];

    if(result != nil)
        NSLog(@"Already checked!");
    else
        NSLog(@"Its unchecked!");

    if([self.checkedIndexPaths member:myIndexPath]{
        checkbox.image = checked;
    }
    else{
        checkbox.image = nonChecked;
    }

    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(25, 5, 70, 20)];
    label.text = [[[sectionContentDict valueForKey:[sectionTitleArray objectAtIndex:[(AFIndexedCollectionView *)collectionView indexPath].section]] objectAtIndex:indexPath.row] objectForKey:@"name"];
    label.font = [UIFont systemFontOfSize:10];
    label.textColor = WhiteColor;
    [cell.contentView addSubview:label];

    return cell;
}

0 个答案:

没有答案