2014-06-05 3 views
1

12 개의 이미지가 있고이 이미지를 UICollectionView에 표시하려는 경우 4 개의 행에 각 행에 3 개의 이미지가 표시됩니다. 여기 컬렉션보기의 셀이 행에 표시되지 않습니다.

내 .H 파일 코드

@interface MyMusic : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate> 
{ 
UICollectionView *_collectionView; 
} 
@end 

이며, 여기 내하는 .m 파일 코드를 잘 작동

- (void)viewDidLoad{ 
enter code hereUICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
[flowLayout setItemSize:CGSizeMake(100, 100)]; 
[flowLayout setMinimumLineSpacing:5]; 
[flowLayout setMinimumInteritemSpacing:5]; 
[flowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)]; 
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 

_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10,238, 300, 200) collectionViewLayout:flowLayout]; 
_collectionView.backgroundColor = [UIColor redColor]; 
[_collectionView setDataSource:self]; 
[_collectionView setDelegate:self]; 
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"]; 
[self.view addSubview:_collectionView]; 
} 


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 
return 4;} 

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

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
enter UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; 

cell.backgroundColor=[UIColor greenColor]; 
return cell; 
} 

코드를 위하지만 내 출력이 오지 않습니다 적절한

는 내가이 문제를 해결 할 수있는 방법 중 하나가 나를 도울 수있는이

enter image description here

처럼 보이는?

+0

줄 간격을 제거하거나 컬렉션보기 너비를 늘리거나 항목 크기를 줄입니다. –

답변

1

귀하의 UICollectionView 폭은 300 점, 그리고 당신의 품목의 폭은 100 점입니다. Interitem 공간 만이 열을 볼 이유 즉, 5 점, 그래서

100*3 + 5*2 = 310. 

입니다.

예를 들어 290

대한 세포의 폭이 조금 작은을 확인 또는 0으로 간격을 interitem 설정

기본 규칙 - 당신의 UICollecitionView 폭이 크거나 당신의 세포의 합과 동일해야 widths + interitem spacing

+0

Thx. 내 시간을 많이 아끼다. –

0

교체

[flowLayout setItemSize:CGSizeMake(100, 100)]; 

[flowLayout setItemSize:CGSizeMake(75,100)]; 

나는 시험 사용 목적으로 75를 사용하고 있으며 iphone screen.so를 고려하여 열의 폭이 동일합니다.

그러나 하드 코딩 된 값은 사용하지 않아야합니다.

관련 문제