I am beginner of iphone, in my code getting run time error of Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isResizable]: unrecognized selector sent to instance 0x6e6e300'
my code is
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path=[[NSBundle mainBundle] pathForResource:@"Animalfile" ofType:@"plist"];
NSDictionary *dict=[NSDictionary dictionaryWithContentsOfFile:path];
NSArray *animal=[dict valueForKey:@"image"];
NSLog(@"print:%@",dict);
NSLog(@"hello:%@",animal);
UIImage *img=[animal objectAtIndex:currentImage];
[animalphoto setImage:img];
}
give any suggestion and source code which is apply in my code....
The problem happens when you attempt treating a string as an image:
UIImage *img = [animal objectAtIndex:currentImage];
The value inside the animal
array cannot be an image, because the array comes from a dictionary dict
that you read from a file using the dictionaryWithContentsOfFile:
method. This method will create objects of types NSString
, NSData
, NSDate
, NSNumber
, NSArray
, or NSDictionary
. UIImage
is not on the list of types that can be created by the dictionaryWithContentsOfFile:
method, so your cast is invalid.
From the error message it appears that you are getting an NSString
instead of UIImage
. Check the value of that string to see what it represents: it is probably a URL, a file name, or some other form of identifier that can be used to obtain an image. Depending on what's in the string, change your program to load img
rather based on the value of the string. Perhaps the code should be
UIImage *img = [UIImage imageNamed:[animal objectAtIndex:currentImage]];
but it is impossible to tell for sure without knowing the value of your string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With