简体   繁体   中英

How to get UIImage from NSDictionary in objective c

I have searched more and more but didn't get the perfect solution. I have saved an image in a dictionary.

@{
   ......
   @"PrdImg":[UIImage imageNamed:[image objectAtIndex:indexPath.row]
   ......
 };

The image data saved perfectly. I checked it. But when I want to get this data from the dictionary then an exception encountered. The retrieving code is giving below.

PoctImage.image = [UIImage imageNamed:PrdDetailsDic[@"PrdImg"]];

The encountered exception is -

'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x7f9428e4e930'

I have also read more document about the exception. But didn't get the specific solution.

Now I want to know how can I get the image data from the dictionary. What is the specific syntax for getting the image from the dictionary.

The initializer UIImage imageNamed: is looking for the image in your main bundle, and since you've got it in a dictionary it won't find it. If you're actually storing a UIImage in the dictionary, why not just say...

PoctImage.image = PrdDetailsDic[@"PrdImg"];

I also suspect there's an issue with trying to save an image to the dictionary in the way you specify, for the same reason. It seems like that one should be...

@{
......
@"PrdImg":[image objectAtIndex:indexPath.row];
......
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM