Reputation: 31
I am receiving url of images from a API and these images i want to show on collection view.
Here is my code
NSString *str = [imgArray objectAtIndex:indexPath.item];
frstUrl=[NSURL URLWithString:str]; // <-- (APP Crash here )
[imageView setImageWithURL:frstUrl
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[imageView setImageWithURL:frstUrl];
Error message:
[__NSArrayI length]: unrecognized selector sent to instance 0xd769560
The NSLog
of the str
object returns:
str=( ( "hello.com/projects/newapp/uploads/…;, "hello.com/projects/newapp/uploads/…;,
Upvotes: 0
Views: 361
Reputation: 438152
That error is telling you that the object that you retrieved from imgArray
was not a NSString
, but rather was, itself, an NSArray
. Examine what you retrieved (either NSLog
it or examine it in the debugger) and you'll see that it's an array.
For example, if the associated object in imgArray
was returning, itself, another array, then you'd have to grab the details from that. If for example, the first item in that array was the image URL string, then you'd do something like:
NSArray *imgDetailsArray = imgArray[indexPath.item];
// let's assume that the first item in that array was the URL string, so let's grab the first item
NSString *str = imgDetailsArray[0];
// now we can use that string
frstUrl=[NSURL URLWithString:str];
[imageView setImageWithURL:frstUrl
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[imageView setImageWithURL:frstUrl];
Upvotes: 1