I am using collection view for view.
Allows you to add sections to the collection view later.
Then, I would like to tap the button attached to the added section so that I can select and view each photo from the camera roll.
For now, you can add a section and select a photo from the camera roll to display it, but when you select a photo, the selected photo for all sections is displayed.
I think it's probably because I updated all the data in the collection view in reloadData...
// Processing after image selection
- (void) imagePickerController: (UIImagePickerController*)picker didFinishPickingMediaWithInfo: (NSDictionary*) info
{
NSLog (@ "After Image Selection");
UIImage* originalImage=(UIImage*) [ info objectForKey: UIImagePickerControllerOriginalImage];
UIImage*editImage=(UIImage*) [ info objectForKey: UIImagePickerControllerEditedImage];
UIImage* saveImage;
if(editImage){
saveImage=editImage;
} else{
saveImage=originalImage;
}
// Display the selected image here
[self addSelectedPicture:self item:saveImage]
[picker dismissViewControllerAnimated:YES completion:nil];
// If you do not reload here, it will not appear when you return after selecting the image.
self.collectionView reloadData;
// [self.collectionView reloadSections: NSIndexSetindexSetWithIndex:0];
}
- (void) addSelectedPicture: (SubjectViewController*) controller item: (UIImage*) item
{
[_images addObject:item];
self.collectionView reloadData;
// [self.collectionView reloadSections: [NSIndexSetindexSetWithIndex:0]];
}
- (void) addItemViewControllerDidFinish2: (AddDateViewController*) controller item: (NSString*) item
{
if(!_objects4){
_objects4 = [[NSMutableArray alloc] init];
}
[_objects4 insertObject: item atIndex:0];
[_sectionDates insertObject: controller.makeDate.date atIndex:0];
// ReloadData here will update the entire section every time it is added
[_collectionView reloadData];
// If you do the following, you will get an error because there is no section at first.
// [self.collectionView reloadSections: [NSIndexSetindexSetWithIndex:0]];
[self-dismissViewControllerAnimated: YES completion: NULL]
}
// The image to be displayed in the cell of the collection
- (UICollectionViewCell*) collectionView: (UICollectionView*) collectionView cellForItemAtIndexPath: (NSIndexPath*) indexPath
{
UICollectionViewCell*cell;
cell=[collectionView requestReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView* imageView= (UIImageView*) [cell viewWithTag:1];
imageView.image=_images [indexPath.row];
return cell;
}
How do I add a section and display each individual image in that section?
I'd like someone to tell me.
Thank you for your cooperation.
You seem to be holding the selected image in a one-dimensional array.
If you want to add a section instead of a cell, wouldn't it be better to keep it in a two-dimensional array?
One-dimensional array
// When the section changes, the row returns to zero, so the same position is obtained.
_images [indexPath.row];
2D array
//Keep images per section
_images [indexPath.section] [indexPath.row];
----------
[_images addObject:item];
Has this been corrected?
Place the array in the array, so
[_imagesaddObject:@[item]];
or
_images[0]=@[item];
// This is what it looks like when you write it down.
NSMutableArray*array= [NSMutableArray new];
array addObject:item;
[_images addObject:array];
The description is similar to .
You need to change the subscripts from the example above, but
The implementation described in the question does not get indexPath
in addSelectedPicture
, so
I think you will need to consider that.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.