簡體   English   中英

添加新單元格時更新集合視圖

[英]Update Collection View when new cell is added

在我的應用程序中,我一張一張地捕獲圖像,我在最后一個索引中顯示了“添加更多”單元,添加新圖像后,我希望此“添加更多”單元可見,在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]) {

        value=@"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];
    }

}

添加以下方法,並在您要添加新單元格的地方調用它。

-(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];
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM