这个是我自己琢磨出来的办法 其他的就不知道了
在拿到数据后 返回对应的数据
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;
}