25 Mar 2017

Collection View ***Number of cells fixed in any Device (With Datasource & Delegate Methods)...



Collection View Number of cells fixed in any Device (With Datasource & Delegate Methods)...

Add CollectionView delegates before coding...

 /* First register nib  ======>>> */

    
- (void)viewDidLoad {
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    [self.controlCollectionView registerNib:[UINib nibWithNibName:@"ControlCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"CustomCell"];


}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 8;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
     MYControlModel *controlModelObj = [self.controlArrays objectAtIndex:indexPath.row ];
    ControlCollectionViewCell *cell = [self.controlCollectionView dequeueReusableCellWithReuseIdentifier:@"CustomCell" forIndexPath:indexPath];
    
    [cell.textLabel setText:controlModelObj.controlName];
    
    cell.collectionImage.image = [UIImage imageNamed:@"default_image"];
       
    return cell;
}
//Number of cell were fixed using this method*********************************

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((CGRectGetWidth(collectionView.frame)/3)-30,(CGRectGetWidth(collectionView.frame)/3)-30);
}


//****************************************************************************
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    

    _selectedIndexPath = indexPath;
    
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
    [self performSegueWithIdentifier:@"ControlDetail" sender:self];
    

}

No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0