0

The code below works fine if I give statically but

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"http://4cing.com/mobile_app/uploads/pageicon/6.jpg"]]]];

Same code - I am passing the image url name dynamically it's not working

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]]]];
Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Anjaneyulu
  • 187
  • 1
  • 2
  • 14

3 Answers3

0
NSMutableArray *imagename = [[NSMutableArray alloc] initWithObjects:@"http://4cing.com/mobile_app/uploads/pageicon/6.jpg", nil];
UIImageView *imgDescView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 200, 200)];

imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
                                            [NSURL URLWithString:[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]]]]];

it is working ... i think u r not creating array properly.

K. Jaiswal
  • 208
  • 2
  • 5
0

You need to verify the NSArray contents. Log out the objects of the array:

NSLog(@"imagename = %@",[imagename description]);

Also, a side-note - might want to think about loading that image dynamically. I wrote a class that makes this pretty painless:

https://stackoverflow.com/a/9786513/585320

The answer is geared toward using in TableViews (where lag would really hurt performance), but you can (and I do) use this for any web image loading. This keeps the UI fluid and is very fast.

Community
  • 1
  • 1
LJ Wilson
  • 14,445
  • 5
  • 38
  • 62
0

Hi create url in this manner

[NSURL URLWithString:[[NSString stringWithFormat:@"%@",[imagename objectAtIndex:0]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]

i think it will work and will resolve ur problem.

Naresh
  • 363
  • 1
  • 18