Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sai Kiran Dasika
Courses Plus Student 7,278 PointsProblem in Ribbit app. ImageViewController
Hey guys there is a problem in the Ribbit app in the imageViewController I am not able to load the picture into the viewController. The code for the following viewController is pasted below:
- (void)viewDidLoad
{
[super viewDidLoad];
PFFile *imageFile = [self.message objectForKey:@"file"];
NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];
self.imageView.image = [UIImage imageWithData:imageData];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
if ([self respondsToSelector:@selector(timeout)]) {
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
}
else {
NSLog(@"Error: selector missing!");
}
}
#pragma mark - Helper methods
- (void)timeout {
[self.navigationController popViewControllerAnimated:YES];
}
2 Answers
Trevor Gerzen
2,749 PointsDo you have the actual URL defined some where else? I don't see it here in your code?
Rob Randell
13,809 PointsIs the app crashing because it is getting a 'nil' value for the 'imageFileUrl' variable. If that is the case, you can tweak the code slightly from
PFFile *imageFile = [self.message objectForKey:@"file"];
NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];
self.imageView.image = [UIImage imageWithData:imageData];
to
//Method from Parse documentation
PFFile *imageFile = [self.message objectForKey:@"file"];
NSData *imageData = [imageFile getData];
self.imageView.image = [UIImage imageWithData:imageData];
Seems to work fine for me and the app works as it should.