2015-01-27 8 views
0

Я новичок в использовании UICollectionView, так как я использую UITableView, поэтому заранее извиняюсь.Ячейка 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

Смежные вопросы