UICollectionView with only 1 vertical "column" still current at 2 columns

I created what I considered the base UICollectionView using xCode 5, iOS 7, Storyboards, AutoLayout OFF, however I get strange results.

I was hoping to create one “column”, that is, all cells stacked vertically, not side by side (for example, TableView):

| 1 |

| 2 |

| 3 |

| 4 |

| 5 |

However, I get 2 columns similar to this (which I can only see if I scroll horizontally):

| 1 | | 2 |

| 3 | | 4 |

| 5 |

My CollectionView has the same width as my cells, 1 section, no inserts, no headers, scroll direction = vertical, layout = stream.

EDIT: I tried adding 5 cells through the Storyboard, and they lined up the way I want, but still do not line up when adding programmatically ...

EDIT2: FYI, UICollectionView, - , 4x4

" "?

+4
3

-(CGSize)collectionView:layout:sizeForItemAtIndexPath: UICollectionViewDelegateFlowLayout. . , 2 , .

(.. , , ) -(UIEdgeInsets)collectionView:layout:insetForSectionAtIndex:

+2

, , : UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout. , :

    -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return numberOfItems;
    }
    -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = (UICollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 
//configure your cell the way you want
    return cell;
}

, , View , ( + + )

cellForItemAtIndexPath:

    CGRect a =cell.frame;
    a = GCRectMake(0,96*[indexPath.item intValue],113,96);
    cell.frame = a;
0

StoryBoard :

  • , CollectionView "" " " ""
  • " " ( "" )
  • Adjust the LEFT and RIGHT values ​​in the Section Inserts section. Increasing values ​​should adjust the "gaps" between the left and right cells. When the gap becomes too large to fit multiple cells on the same line, the collection view is automatically set to one cell on the line.

enter image description here

enter image description here

0
source

All Articles