2017-04-10 7 views
0

私のアプリケーションでは、イメージを1つずつキャプチャしています。最後に「追加」を示すセルがあります。新しいイメージが追加されたら、 3〜4枚の画像の後に「追加する」セルが表示されなくなります。 [追加]セルが常に表示されるようにコレクションビューを更新するにはどうすればよいですか。 はありがとうございました:)イメージを追加する新しいセルが追加されたときにコレクションコレクションのビューが表示される

コード:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 

CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 


if (indexPath.row == [imageArray count]) { 

    cell.ImageImg.image =[UIImage imageNamed:@"plus.jpg"]; 
    cell.DeleteBtn.hidden=true; 
    [cell.ImageImg.layer setBorderColor: [[UIColor clearColor] CGColor]]; 
    [cell.ImageImg.layer setBorderWidth: 0.5]; 

} 

else 
{ 
    cell.DeleteBtn.hidden=false; 

    cell.ImageImg.image=[imageArray objectAtIndex:indexPath.row]; 
    [cell.ImageImg.layer setBorderColor: [[UIColor blackColor] CGColor]]; 
    [cell.ImageImg.layer setBorderWidth: 0.7]; 
    [cell.DeleteBtn addTarget:self action:@selector(RemovePrssd:) forControlEvents:UIControlEventTouchUpInside]; 

} 

return cell; 
} 
-(void)RemovePrssd:(id)sender{ 

UIView *senderButton = (UIView*) sender; 
NSIndexPath *indexPath = [_ImageCollectionVIew indexPathForCell: (UICollectionViewCell *)[[senderButton superview]superview]]; 

[imageArray removeObjectAtIndex:indexPath.row]; 
[_ImageCollectionVIew deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; 
} 
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
    if (indexPath.row == [imageArray count]) { 

     [email protected]"0"; 
     [_videoController.view removeFromSuperview ]; 
     UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsEditing = YES; 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     [self presentViewController:picker animated:YES completion:NULL]; 
    } 

} 
+1

関連コードを表示してください。 – Lion

+0

イメージを貼り付けることはできますか? –

+0

@Lionコードを追加しました:) –

答えて

0

は、法の下に追加され、新しいセルを追加しているところ、それを呼び出します。

-(void)scrollToBottom 
{ 
CGFloat collectionViewContentHeight = _ImageCollectionVIew.contentSize.height; 
CGFloat collectionViewFrameHeightAfterInserts = _ImageCollectionVIew.frame.size.height - (_ImageCollectionVIew.contentInset.top + _ImageCollectionVIew.contentInset.bottom); 

if(collectionViewContentHeight > collectionViewFrameHeightAfterInserts) { 
    [_ImageCollectionVIew setContentOffset:CGPointMake(0,_ImageCollectionVIew.contentSize.height - _ImageCollectionVIew.frame.size.height) animated:NO]; 
    } 
} 
関連する問題