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.!
Question
I am developing an image gallery which permits to select some pictures from the iPhone and display them.
Some explanations about this gallery:
UITableView
displays the different directories which contain iPhone picturesUICollectionView
with the different pictures from the selected directoryUITableView
How this gallery is implemented:
ALAssetsGroup
in an NSMutableArray
named directoriesDataUITableView
.ALAsset
contained in this directory in an NSMutableArray
named picturesData.UICollectionView
from picturesData.NSMutableArray
named desiredPictures.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 !
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)
objc_msgSend + 6
frame #0: 0x39764b26 libobjc.A.dylib
frame #1: 0x00195f1a MyProject-[Picture getFullImage](self=0x176ebb40, _cmd=0x005de393) + 310 at Picture.m:211
-[Picture getCroppedImage](self=0x176ebb40, _cmd=0x005da2b4) + 68 at Picture.m:154
frame #2: 0x001959bc MyProject
frame #3: 0x001f9a82 MyProject__68-[ImageCropViewController sliderContentsAddContent:ToSlider:AtPage:]_block_invoke(.block_descriptor=0x17637000) + 50 at ImageCropViewController.m:1020
_dispatch_call_block_and_release + 10
frame #4: 0x39c4cd1a libdispatch.dylib
frame #5: 0x39c53d70 libdispatch.dylib_dispatch_root_queue_drain + 220
_dispatch_worker_thread2 + 56
frame #6: 0x39c53f58 libdispatch.dylib
frame #7: 0x39d8edbe libsystem_pthread.dylib`_pthread_wqthread + 298
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.!