ios - Loading images from documents directory to UICollectionView -
i having problem loading images uicollectionview. trying take photo , save name documents folder, , want photo appear in collection view after photo taking dismisses.
up until images being saved in documents folder , automatically added _stepimagesarray can't figure out how load images , populate uicollectionview them.
please help, has been while trials , errors :)
stepscollectionviewcontroller.m
- (void)viewdidload { [super viewdidload]; _stepimagesarray = [[nsmutablearray alloc] init]; } #pragma mark - uicollectionview settings - (nsinteger)collectionview:(uicollectionview *)view numberofitemsinsection: (nsinteger)section { return _stepimagesarray.count; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath{ static nsstring *identifier = @"cell"; collectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:identifier forindexpath:indexpath]; cell.imagecell.image = [uiimage imagenamed:[_stepimagesarray objectatindex:indexpath.row]]; cell.labelcell.text = _stepimagesarray[indexpath.row]; return cell; } - (ibaction)takephoto { uiimagepickercontroller *photopicker = [[uiimagepickercontroller alloc] init]; photopicker.delegate = self; photopicker.sourcetype = uiimagepickercontrollersourcetypecamera; [self presentviewcontroller:photopicker animated:yes completion:null]; } - (void)imagepickercontroller:(uiimagepickercontroller *)photopicker didfinishpickingmediawithinfo:(nsdictionary *)info { uiimage *selectedimage = [info valueforkey:uiimagepickercontrolleroriginalimage]; [self.selectedimageview setimage:selectedimage]; arraycount = self.stepimagesarray.count; nslog(@"array count is: %i",arraycount); nsstring *jpgimagename = [nsstring stringwithformat:@"documents/foldername_%@%i.jpg", passedstepname, arraycount+1]; nsstring *jpgimagenameforarray = [nsstring stringwithformat:@"foldername_%@%i.jpg", passedstepname, arraycount+1]; nsstring *jpgpath = [nshomedirectory() stringbyappendingpathcomponent: jpgimagename]; [uiimagejpegrepresentation(selectedimage, 0.1) writetofile:jpgpath atomically:yes]; // let's check see if files written... // create file manager nserror *error; nsfilemanager *filemgr = [nsfilemanager defaultmanager]; // point document directory nsstring *documentsdirectory = [nshomedirectory() stringbyappendingpathcomponent:@"documents"]; // write out contents of home directory console nslog(@"documents directory: %@", [filemgr contentsofdirectoryatpath:documentsdirectory error:&error]); [_stepimagesarray addobject:jpgimagenameforarray]; [photopicker dismissviewcontrolleranimated:yes completion:nil]; } collectionviewcell.h
@interface collectionviewcell : uicollectionviewcell @property (weak, nonatomic) iboutlet uiimageview *imagecell; @property (weak, nonatomic) iboutlet uilabel *labelcell; @end
Comments
Post a Comment