Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

The problem is i have a UICollectionView and i have a custom cell inherited from UICollectionViewCell.Now what i have on UICollectionView is two buttons left and right when i click the right button the cell should change and the next one should come in picture.The Cell has a TextView.And on click of right button the next cell(with textview) should be in picture.similarly on click of left it should display previous one.

Thanks and best regards.

CellforRow:

-(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;
}
share|improve this question
up vote 0 down vote accepted
-(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
}

use your custom cell type at this line

UICollectionViewCell *cell= [collectionView cellForItemAtIndexPath:IndexPath];

Hope this will help

share|improve this answer
    
you can easily get cell using collectionView cellforrowatIndexPath like tableView – Warewolf Jun 13 '13 at 7:12
    
Thank You So much for your Efforts. +1 – user2478518 Jun 13 '13 at 11:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.