2016-09-30 4 views
0

Ich habe eine UICollectionView mit benutzerdefinierter Höhe und Breite, aber wenn ich die App starte, sind alle Zellen, die anfänglich sichtbar sind, perfekt in Bezug auf meine Höhe und Breite eingestellt, aber wenn ich runterscrollen reduziere die Zellenbreite. Here is the screenshotUICollectionView Zellenbreite Problem

Hier werden die Methoden zur Festlegung von Höhe und Breite sind, Abstand usw.

- (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]; 

} 

Antwort

0

Entfernen Sie diese Zeile aus dieser Methode

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

ich es gelöst haben, aber keiner Weise Dank für Ihre Antwort. –

Verwandte Themen