UICollectionView delegate's tap method not getting called

后端 未结 8 1650
梦毁少年i
梦毁少年i 2021-01-03 20:50

I have a collection view, the datasource delegate works well, but UICollectionViewDelegate:

-(void)collectionView:(UICollectionView *)collection         


        
8条回答
  •  猫巷女王i
    2021-01-03 21:07

    in ur .h file, import CellViewController and add delegate

    #import "myColleCell.h"
    
    UIViewController
    

    in ur .m file,add the following codes to ur ViewDidLoad,

    UINib *cellNib = [UINib nibWithNibName:@"myColleCell" bundle:nil];
    [myCollectionView registerNib:cellNib forCellWithReuseIdentifier:@"myColleCell"];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(220, 220)];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [myCollectionView setCollectionViewLayout:flowLayout]; 
    

    and setup cell with ur CellViewController

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *identifier= @"myColleCell";
        myColleCell *cell = (myColleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    
        [cell setupCell:[dataArray objectAtIndex:indexPath.row]];
        //setup cell function methods placed in your CellViewController
        return cell;
    
    }
    

    and finally make sure that your cellView, collectionView are set user interactive to YES

提交回复
热议问题