我有一個集合視圖。我想爲每個單元格上傳五張圖片,並且如果已經存在,則從JSON
獲取圖片到該單元格中,如果沒有使用UIImagePicker
,則UIButton
動作必須一個一個地上傳五張圖片,它可以是四張,三張或單張圖片。UICollectionView從UiImagePickerController獲取圖像
如果圖像已經存在,則取代以前的圖像。這樣
東西現在我要替換和更改這些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");
}];
我怎樣才能做到這一點?
你必須設置布爾值來檢查新圖像選擇或現有圖像更改 –
我該如何更改圖像與附加到單元格的按鈕..? – Nivesh
只需等幾分鐘,我會給你完整的代碼。 –