У меня есть массив с 10 элементами. Я хочу, чтобы отобразить их на UICollectionView как 3 в каждой строке, так что они будут какИспользование UICollectionView В iphone
A B C
D E F
G H I
J
Теперь я использую следующий код
#pragma mark - UICollectionView Datasource
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
return 3;
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return [self.btnArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Buttons *btn = [self.btnArray objectAtIndex:(indexPath.section * indexPath.row)];
NSURL* aURL = [NSURL URLWithString:btn.imagePath];
NSData* data = [[NSData alloc] initWithContentsOfURL:aURL];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:data]];
return cell;
}
#pragma mark – UICollectionViewDelegateFlowLayout
// 1
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize retval = CGSizeMake(75, 75);
return retval;
}
// 3
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(50, 20, 50, 20);
}
Однако когда я ударил
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
Это дает me погрешность
NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
что не так?
Звуки для меня, как это говорит вам, как это исправить. Вы сделали одну из этих вещей? –
@CarlNorum http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12 Я использую предварительно выполненный макет? –