0

问题是我有一个UICollectionView,我有一个继承自的自定义单元格UICollectionViewCell。现在我有UICollectionView两个按钮,当我单击右侧按钮时,单元格应该改变,下一个应该出现在图片中。单元格有一个 TextView 。点击右键,下一个单元格(带有文本视图)应该在图片中。类似地点击左键,它应该显示上一个。

谢谢和最好的问候。

细胞换行:

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView == self.myCV) {
        myCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];

        if (cell == nil)
        {
            NSArray *xibPath = [[NSBundle mainBundle] loadNibNamed:@"myCollectionView" owner:self options:nil];
            cell = [xibPath objectAtIndex:0];
        }
        return cell;
    }
    else if (collectionView == self.myCV2)
    {
        myCC2 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL2" forIndexPath:indexPath];

        if (cell == nil)
        {
            NSArray *xibPath = [[NSBundle mainBundle] loadNibNamed:@"myCC2" owner:self options:nil];
            cell = [xibPath objectAtIndex:0];
        }
        return cell;
    }
    return 0;
}
4

1 回答 1

0
-(void)moveCell:(UIButton*)sender
{
    if (sender.tag==0) {
        //move left
        if (count>0) {
            count--;
            NSLog(@"count == %i",count);
            [self snapToCellAtIndex:count withAnimation:YES];//paas index here to move to.
        }
    }else{
        //move right
        if (count<noOfCells-1) {
            count++;
            NSLog(@"count == %i",count);
            [self snapToCellAtIndex:count withAnimation:YES];//paas index here to move to.
        }
    }
}

- (void) snapToCellAtIndex:(NSInteger)index withAnimation:(BOOL) animated
{
    NSIndexPath *IndexPath = [NSIndexPath indexPathForRow:index inSection:0];
    UICollectionViewCell *cell= [_myCollectionView cellForItemAtIndexPath:IndexPath];
    [_myCollectionView scrollToItemAtIndexPath:IndexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:animated];
    UITextView *txtView=(UITextView*)[cell viewWithTag:21];
    [txtView becomeFirstResponder]; //in current cell with index
}

在此行使用您的自定义单元格类型

UICollectionViewCell *cell= [collectionView cellForItemAtIndexPath:IndexPath];

希望这会有所帮助

于 2013-06-13T05:43:49.787 回答