UICollectionView 实现添加图片

这个是我自己琢磨出来的办法  其他的就不知道了  

在拿到数据后 返回对应的数据

for(NSDictionary* dictin_moxing.pics) {

        Model * model = [Model GetMessageWithDict:dict];

        [self.collectionarrayaddObject:model];

    }

//这个是添加一个假数据 也就是 你的图片后面的加号的那个cell

    LNPicModel * model =[[LNPicModel alloc]init];

    [self.collectionarray addObject:model];

    [self.collectionView reloadData];


//这个是cell点击是判断有没有图片

- (void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{

    LNPicModel* model=_collectionarray[indexPath.item];

    if(model.picUrl){

        NSLog(@"点击的是有图片的");

    }else{

        [self Loadpicturecontroller];

    }

}

在cell里面给图片赋值

- (void)configureCellWithModel:(LNPicModel*)model{

    if(model.picUrl) {

         NSString *imgUrl = [model.picUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

        [self.MessageImage sd_setImageWithURL:[NSURL URLWithString:imgUrl]];

        self.deletaBtn.hidden=NO;

    }else{

        self.MessageImage.image = [UIImage imageNamed:@"AddWorkImage"];

        self.deletaBtn.hidden=YES;

    }

}

这里记一下  我做的是能添加的图片个数是后台决定的 所以返回的个数是后太返回的个数

- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section {


    if (self.collectionarray.count >_picCount) {

        return_picCount;

    }else{

        return _collectionarray.count;

    }

    return 0;

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容