ios - Convert nested NSArray to array of images for UIScrollview based on selection made -
i have array in plist holds 3 arrays of images follows:
<dict> <key>imagearrays</key> <array> <array> <string>bears.png</string> <string>babybear.png</string> <string>mamabear.png</string> </array> <array> <string>birds.png</string> <string>babybirds.png</string> <string>mamabirds.png</string> </array> <array> <string>chimps.png</string> <string>babychimp.png</string> <string>mamachimp.png</string> </array> </array> based on selection made within icarousel want display 1 of arrays in uiscrollview on view controller. i'm passing selection on via following:
[passinfo myimagearray] //myimagearray array selected. my question how pictures array selected array feeds uiscrollview? passed entire array need convert image names nsstrings , put in new array? if so, how?
edit: give more info on i've done already.
so, i've accessed outer array plist this:
-(void)awakefromnib self.stopimagearray = [rootdictionary objectforkey:@"imagearrays"]; determined selected array this:
-(void)didselectitematindex arraychosen = [nsarray arraywithobject:[self.stopimagearray objectatindex:self.carousel.currentitemindex]]; [info setmyimagearray:arraychosen]; [allinfo addobject:info]; passed via class file this:
@property (nonatomic, strong) nsarray *myimagearray; and pulled selected array on final view controller this:
chosenarray = [nsarray arraywitharray:[passinfo myimagearray]]; so think i've got correct nsarray need, i'm not sure how convert array an array filled images. don't need create nsarray objects or convert image names uiimage?
first access internal array of imagearrays key. lets have this:
nsarray* arraywitharrays = // store first outer <array> then can of arrays inside indexes:
nsarray* imagearray1 = arraywitharrays[0]; nsarray* imagearray2 = arraywitharrays[1]; nsarray* imagearray3 = arraywitharrays[2]; just make sure not go out of bounds on arraywitharrays, can check calling count method or looping through array collection:
nsarray* selectedimagearray; (nsarray* imagearray in arraywitharrays) { // should wrap line conditional selectedimagearray = imagearray; } fill uiscrollview selectedimagearray or of imagearrayx variables. of course can store in property in view controller class.
if want store uiimage objects in array, first need loop through imagearray strings , create objects. can accomplish following code:
nsmutablearray* images = [nsmutablearray array]; (nsstring* imagename in imagearray { [images addobject:[uiimage imagenamed:imagename]]; } however advise against storing whole uiimage objects in array. better store strings, now, call imagenamed: method everytime need load image.
Comments
Post a Comment