2017-04-10 75 views
0

在我的應用程序中,我逐一捕獲圖像,我在最後一個索引處顯示「添加更多」單元格,添加新圖像時,我想要「添加更多」單元格可見,在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]; 
    } 
} 
相關問題