2

I try to show a image in my iphone app but it doesn't show. I connect in IB and I check to show a local image, it workd good. I also check the url from image and it is ok. I use the next code:

NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData]; 
imageView.image = image;

and

//Video.h
NSString *urlThumbnail;

and this is my code on the view.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"URLTHUMBNAIL: %@", aVideo.urlThumbnail); 
    NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage *image = [UIImage imageWithData:imageData]; 
    imageView.image = image;
}

NSLog getts on console

URLTHUMBNAIL: http://147.83.74.180/thumbnails/56.jpg

The connections on IB are ok, cause I can display a local image using next code on the same IBAction

UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"barret" ofType:@"png"]];
2
  • 2
    Code looks fine. Check your IBoutlets again, or post more code. Commented May 11, 2010 at 22:39
  • The IBoutlet is ok. And I write this on ViewDidAppear. Commented May 11, 2010 at 22:45

2 Answers 2

1

It can be very helpful to NSLog() yourself some notes about what's really in your variables. If you really do have everything hooked up right in IB, it could be that aVideo.urlThumbnail isn't getting set. I'd like to see that value in the console right before creating your NSURL with it.

Sign up to request clarification or add additional context in comments.

1 Comment

I add the test on the question.
0

First off, since NSData dataWithContentsOfURL: accesses the network, you should consider doing that in the background. Otherwise, your UI may become unresponsive.

You should consider adding some additional logging to check the value of imageData and image. Also, you can call NSData dataWithContentsOfURL:options:error: to see if that's the source of the failure.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.