iphone - Using nested NSDictionary with Picker -
newbie here,
i have single component picker set plist, each item being array, multiple strings in each array app uses.
currently plist structure this:
nsdictionary -> nsarray -> nsstring | | items in picker data each item
but now, want:
nsdictionary -> nsdictionary -> nsarray -> nsstring | | | different picker data sets items in picker data each item
so there multiple sets of picker components show using segmented control etc...
i'm not sure if possible, , hoping save me making many different separate picker controllers.
what has me stumped getting ingested properly
this have now, builds crashes (debug info below):
nsbundle *bundle = [nsbundle mainbundle]; nsstring *plistpath = [bundle pathforresource:@"camerasdatabase" oftype:@"plist"]; nsdictionary *dictionary = [[nsdictionary alloc] initwithcontentsoffile:plistpath]; self.allcameras = dictionary; [dictionary release]; nsarray *cameratypes = [self.allcameras allkeys]; self.camtypes = cameratypes; nsarray *items = [self.camtypes objectatindex:0]; self.cameras = items; nsstring *selectedcamera = [self.cameras objectatindex:0]; nsarray *array = [camslist objectforkey:selectedcam]; self.cameradata = array;
i've tried many different combinations of dictionaries, arrays, , strings i'm sure above code messed up.
it crashes at:
nsstring *selectedcamera = [self.cameras objectatindex:0];
with "-[nscfstring objectatindex:]: unrecognized selector sent instance 0x4e127f0"
it obvious, having nsstring objects (keys) in self.camtypes. not nsarray.
so these lines invalid
nsarray *items = [self.camtypes objectatindex:0]; self.cameras = items; nsstring *selectedcamera = [self.cameras objectatindex:0]; //this line cause of exception.
for fixing write code thing this
nsbundle *bundle = [nsbundle mainbundle]; nsstring *plistpath = [bundle pathforresource:@"camerasdatabase" oftype:@"plist"]; nsdictionary *dictionary = [[nsdictionary alloc] initwithcontentsoffile:plistpath]; self.allcameras = [dictionary valueforkey:@"key "];//key accesing inner dictionary [dictionary release]; nsarray *cameratypes = [self.allcameras allkeys]; self.camtypes = cameratypes; nsarray *items = [self.allcameras valueforkey:[self.camtypes objectatindex:0]]; self.cameras = items; nsstring *selectedcamera = [self.cameras objectatindex:0]; nsarray *array = [camslist objectforkey:selectedcam]; self.cameradata = array;
so in above code self.allcameras dictionary having arrays corresponding different key (cameratypes in self.camtypes).
Comments
Post a Comment