2016-09-30 3 views
0

У меня есть UICollectionView с пользовательской высотой и шириной, но когда я запускаю приложение, все те ячейки, которые изначально видны на экране, отлично настроены относительно моего значения Height и Width, но когда я прокручиваю вниз, уменьшаем ширина ячейки. Here is the screenshotUICollectionView Cell Width Issue

Вот методы для установки высоты и ширины, Spacing и т.д.

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 5.0; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 5.0f; 
} 

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.collectionView setNeedsLayout]; 
    [self.collectionView layoutIfNeeded]; 
    CGFloat width = self.collectionView.frame.size.width; 
    return CGSizeMake((width/2)-5, 220); 
} 


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 
    return [listOfRetailers_ count]; 
} 
-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ 
    BDRetailerCollectionViewCell *newCell = (BDRetailerCollectionViewCell*)cell; 
    UIFont *font = newCell.brandName.font; 
    [newCell.brandName setFont:[font fontWithSize:12]]; 
    [newCell setNeedsLayout]; 
    [newCell layoutIfNeeded]; 

} 

ответ

0

Удалите эту строку из этого метода

(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
[self.collectionView setNeedsLayout]; 
[self.collectionView layoutIfNeeded]; 
+0

Я решил его, но никак спасибо за ваш ответ. –