2015-01-27 2 views
0

UITableView를 사용하고 있으므로 UICollectionView를 처음 사용하기 때문에 미리 사과드립니다.UICollectionView 셀이 화면에서 정렬되어 있습니까?

어쨌든 몇 가지 간단한 코드가 있지만 몇 가지 이유 때문에 아직 익숙하지 않은 일부 셀은 다음 단계로 이동하지 않고 화면에 표시되지 않습니다.

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

    array = [ [NSMutableArray alloc] initWithObjects:@"Apple", @"Is", @"The", @"Bomb", @".com", @":D", nil]; 
} 

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

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

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return array.count; 
} 

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

    UILabel *label = (UILabel *)[cell viewWithTag:100]; 

    label.text = [array objectAtIndex:indexPath.row]; 

    [cell.layer setBorderWidth:2.0f]; 
    [cell.layer setBorderColor:[UIColor whiteColor].CGColor]; 

    [cell.layer setCornerRadius:10.f]; 

    return cell; 
} 

enter image description here

은 "폭탄"과 ".COM"와 셀에 무슨 일이? 왜 화면이 잘리지 않습니까?

+0

컬렉션보기의 프레임은 무엇입니까? 그걸 어떻게 세웠습니까? – rdelmar

답변

1

컬렉션보기에서보기 제약 조건을 설정해야합니다. Autolayout 프로그래밍을 확인하여 UICollectionView에 대한 제약 조건을 설정하십시오.

+0

UITableView에 대한 제약 조건을 설정하는 방법을 알고 있지만 UICollectionView에 대한 제약 조건을 어떻게 알 수 있습니까? 바보 같은 것! :) – Pangu

관련 문제