user1490535
user1490535

Reputation: 175

how to solve run time error of [__NSCFString _isResizable]: unrecognized selector sent to instance?

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....

Upvotes: 5

Views: 4259

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

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.

Upvotes: 11

Related Questions