【发布时间】:2016-12-27 10:23:11
【问题描述】:
我有一个收藏视图。我想为每个单元格上传五张图片,如果已经从JSON 中获取图片,如果在UIButton 上不使用UIImagePicker,则必须一张一张上传五张图片,可以是四张,三张或单个。
如果已经存在图像,则替换以前的图像。像这样的
现在我想替换和更改这些JSONImages。
我在cellForRowAtIndexPath 中做过类似的事情
MG_PhotoCollectionViewCell *cell = (MG_PhotoCollectionViewCell *) . [self.collectionView dequeueReusableCellWithReuseIdentifier:kProductCellIdentifier forIndexPath:indexPath];
NSString *myPatternString = [self.dataArray objectAtIndex:indexPath.item];
NSLog(@"myPatternString %@",myPatternString);
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:myPatternString]];
cell.imageView.image = [UIImage imageWithData:data];
cell.backgroundColor = [UIColor lightGrayColor];
cell.overlayButton.layer.cornerRadius = cell.overlayButton.frame.size.height/2;
cell.overlayButton.clipsToBounds = YES;
[cell.overlayButton addTarget:self action:@selector(getImages:) forControlEvents:UIControlEventTouchUpInside];
cell.overlayButton.tag = indexPath.item;
它的选择器控制器为
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(nonnull NSDictionary<NSString *,id> *)info{
// UIImage *imagepick = info[UIImagePickerControllerEditedImage];
UIImage *image= info[UIImagePickerControllerEditedImage];
if (!image) image = info[UIImagePickerControllerOriginalImage];
[self.dataArray addObject:image];
[self.collectionView reloadData];
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"Finished image picking");
}];
我怎样才能做到这一点?
【问题讨论】:
-
您必须设置布尔值以检查新图像选择或现有图像更改
-
如何使用附加到单元格的按钮更改图像..?
-
稍等几分钟,我会给你完整的代码。
-
谢谢哥们...等待
-
gist.github.com/himanshu-benzatine/… @Dheeraj 参考这个文件
标签: ios objective-c uicollectionview uiimagepickercontroller