ios - Manual VS Automatic Array Clarification -
in app, i'm going creating array of objects manually creating equal array objects stored in reference folder. create automatic array contentsofdirectoryatpath.
the problem when reference array later in collection view, cellforitematindexpath. manually created array runs fine automatic array not in same format , throws error.
the difference manually created array has 3 objects , automatically created array has 1 object, shown in log set of parenthesis. how may automatically created array add together each folder object individually can array 3 objects did manually created array? in advance time.
manually create targetarray
//@interface @property (nonatomic, strong) nsarray *targetarray; //viewdidload self.targetarray = @[@"one",@"two", @"three"]; nslog(@"target array description test = %@", [_targetarray description]); //returns target array description test = ( "one", "two", "three" )
automatically create array reading reference folder
//@interface @property (nonatomic, strong) nsarray *targetarray; //viewdidload (int = 0; <= [folderarray count] -1; i++) { nsstring *sectionstring = [folderarray objectatindex:i]; nsmutablearray *subfolderarray = [[nsmutablearray alloc] init]; nsarray *targetarray = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:folderpath error:nil]; nslog(@"target array description test = %@", [_targetarray description]); } //returns target array description test = ( ( "one", "two", "three" ) )
cellforrowatindexpath w/error log reference
-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { sheetcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"sheetcell" forindexpath:indexpath]; nslog(@"target array description test = %@", [_targetarray description]); nsstring *sheetstring = [self.targetarray objectatindex:indexpath.row]; error: *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nsarraym stringbydeletingpathextension]: unrecognized selector sent instance 0x78794450' cell.sheetimageview.image = [uiimage imagenamed:sheetstring]; cell.sheetlabel.text = sheetstring; homecoming cell; }
if know "contentsofdirectoryatpath" method homecoming array of objects in single element outer array, "unpackage" inner array by:
nsarray *targetarray = [[[nsfilemanager defaultmanager] contentsofdirectoryatpath:folderpath error:nil] objectatindex:0];
(i'm not @ computer run above through xcode check compiles)
as side note, there fews issues code snippets provided (could typos or copy/paste errors) in assigning local variable called "targetarray" , accessing instance variable called "targetarray" in print statement - not same objects.
ios objective-c arrays nsarray nsfilemanager
No comments:
Post a Comment