1
votes

I'm parsing JSON file in iOS and I'm getting elements in a tableview but when I created (prepareForSegue) to get tableview element I can't get image and I get this error:

unrecognized selector sent to instance 0x7fa3427c5b20 2016-05-05 05:08:43.287 MovieClub[4845:212195] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString size]: unrecognized selector sent to instance 0x7fa3427c5b20'

in this line of code:

self.postt.image =[self.actuatlitDetail objectForKey:@"poster_240x342"];
3
what is poster_240x342 is it name of image or url ? - Prashant Tukadiya
Please share more code so we can help you out. - Mahendra
the objective c don't accept it - wassim wess
any other solution - wassim wess
.m self.prepTimeLabel.text = [self.actuatlitDetail objectForKey:@"original_title"]; self.postt.imageWithName =[self.actuatlitDetail objectForKey:@"poster_240x342"]; - wassim wess

3 Answers

1
votes

If [self.actuatlitDetail objectForKey:@"poster_240x342"] returns NSURL you can use

NSURL *imageURL = [self.actuatlitDetail objectForKey:@"poster_240x342"];
self.postt.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];

If it is NSString then represent URL then

NSString *imageURLString = [self.actuatlitDetail objectForKey:@"poster_240x342"];
self.postt.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageURLString]]];

You can load image in background

__weak typeof(self) weakSelf = self;
dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(aQueue, ^{
    NSURL *imageURL = [weakSelf.actuatlitDetail objectForKey:@"poster_240x342"];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
    dispatch_async(dispatch_get_main_queue(), ^{
        weakSelf.postt.image = image;
    });
});
0
votes

its url value of actuatlitDetail, get the below code,

NSString *imageurl = [self.actuatlitDetail objectForKey:@"poster_240x342"];
NSString *encodedUrlString = [imageurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *imageURL = [NSURL URLWithString: encodedUrlString];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *imag = [UIImage imageWithData:imageData];
self.postt.image = imag;

hope its helpful

0
votes

Set Image Path Then Follow this :

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"Your image url string"]];
UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]];