objective c - How to access object for id -


hiho code-friends,

i created nsmutabledictionary "_favdictionary" picture-data inside. getting key current cell collection-view, contains integer named "key".

flamaincell *cell = (flamaincell *) sender.view; nsuinteger *key = cell.key;  nsstring *instr = [nsstring stringwithformat:@"%lu", (unsigned long)key]; _favdictionary[instr] = storeimage;     - (uiimage *)getfavouriteimages:(nsinteger)index{     return _favdictionary[index]; } 

i beginner in objective-c , not find possibility access dictionary integer value in method "getfavouriteimages". error getting says "nsmutabledictionary doesn't respond objectatindexedsubscript".

can tell me how can access dictionary via integer?

first of all, if indexing integers, use nsarray.

if want use nsdictionary, don't have convert integers strings, can use nsnumber instead.

flamaincell *cell = (flamaincell *) sender.view; nsuinteger *key = cell.key;  nsnumber *innumber = @(key); _favdictionary[innumber] = storeimage;    - (uiimage *)getfavouriteimages:(nsinteger)index{     return _favdictionary[@(index)]; } 

if want use strings, have convert index nsstring too, before indexing:

- (uiimage *)getfavouriteimages:(nsinteger)index{     nsstring *stringindex = [nsstring stringwithformat:@"%@", @(index)];     return _favdictionary[stringindex]; } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -