我有一个UICollectionView,它由一个Cell中的UIImagePickerControl按钮填充,我希望带有按钮的单元格显示整个时间,但我似乎无法显示它。 这是我的代码:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.project.screens count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1) {
Screen* screen = [self.project.screens objectAtIndex:indexPath.row];
static NSString* cellIdentifier = @"ImageCell";
CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.screen = screen;
cell.delegate = self;
return cell;
}else{
static NSString* cellIdentifier = @"ButtonCell";
CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.delegate =self;
return cell;
}
}
我的if语句中的代码应该是什么,以及如何将+1添加到
return [self.project.screens count];
答案 0 :(得分:0)
你几乎就在那里,
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
//Number of elements + 1 for the button
return [self.project.screens count]+1;
}
并在
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1) {
Screen* screen = [self.project.screens objectAtIndex:indexPath.row];
static NSString* cellIdentifier = @"ImageCell";
CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.screen = screen;
cell.delegate = self;
return cell;
}else{
static NSString* buttonCellIdentifier = @"ButtonCell";
CollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:buttonCellIdentifier forIndexPath:indexPath];
cell.delegate =self;
return cell;
}
}