Question

I am developing an image gallery which permits to select some pictures from the iPhone and display them.

Some explanations about this gallery:

  • An UITableView displays the different directories which contain iPhone pictures
  • When the user click on one of these directories: Display an UICollectionView with the different pictures from the selected directory
  • Back button to come back to the UITableView
  • Next button to display the selected images in a new page.

How this gallery is implemented:

  • For each directories found in iPhone pictures, store the ALAssetsGroup in an NSMutableArray named directoriesData
  • Display the directories stored in directoriesData in an UITableView.
  • When the user select one directory : Store each of the ALAsset contained in this directory in an NSMutableArray named picturesData.
  • Display thumbnails in an UICollectionView from picturesData.
  • When the user select a picture, it is stored in a singleton instance of NSMutableArray named desiredPictures.
  • If the user click on the back button, I remove all the objects from the picturesData before display the UITableView.

Now the problem:

I have two different directories of pictures in my iPhone.

Directory A Directory B

I want to select one picture in Directory A and one other in Directory B.

After select them, I click to the next page to display them.

The new page loads the images from the desiredPictures. But when I want display the selected pictures by accessing to the ALAsset of the Directory A, I have an EXC_BAD_ACCESS.

After some test and research in my project, I found that if I do not remove the objects from picturesData (when I press button back), I don't have anymore the EXC_BAD_ACCESS.

But, I need to clean the contents of picturesData because when I fill my UICollectionView it's from the picturesData. And in the case of I access to the directory A and then to directory B, I will have the content of the two directories in the UICollectionView.

So how can I keep ALAsset pointer correct and clean pictureData?

I hope you understand my project and problem.

Thanks !

http://img11.hostingpics.net/pics/581536photo.jpg

Edit:

Backtrace

* thread #29: tid = 0x599a6, 0x39764b26 libobjc.A.dylibobjc_msgSend + 6, queue = 'com.apple.root.high-priority, stop reason = EXC_BAD_ACCESS (code=1, address=0xc)
frame #0: 0x39764b26 libobjc.A.dylib
objc_msgSend + 6
frame #1: 0x00195f1a MyProject-[Picture getFullImage](self=0x176ebb40, _cmd=0x005de393) + 310 at Picture.m:211
frame #2: 0x001959bc MyProject
-[Picture getCroppedImage](self=0x176ebb40, _cmd=0x005da2b4) + 68 at Picture.m:154
frame #3: 0x001f9a82 MyProject__68-[ImageCropViewController sliderContentsAddContent:ToSlider:AtPage:]_block_invoke(.block_descriptor=0x17637000) + 50 at ImageCropViewController.m:1020
frame #4: 0x39c4cd1a libdispatch.dylib
_dispatch_call_block_and_release + 10
frame #5: 0x39c53d70 libdispatch.dylib_dispatch_root_queue_drain + 220
frame #6: 0x39c53f58 libdispatch.dylib
_dispatch_worker_thread2 + 56
frame #7: 0x39d8edbe libsystem_pthread.dylib`_pthread_wqthread + 298

Was it helpful?

Solution

Apple has provided a clean way to do what you are trying to achieve.

Here is the sample code : MyImagePicker

and try to analyze the code and see what they are doing.!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top