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
miles fishman
Courses Plus Student 3,610 PointsIs this the right code to open a image or video on Ribbit? It does not seem to work
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
self.selectedFile=[self.messages objectAtIndex:indexPath.row];
NSString*fileType=[self.selectedFile objectForKey:@"fileType"];
if([fileType isEqualToString:@"image"]){
[self performSegueWithIdentifier:@"showImage" sender:self];
}
else {
PFFile*videoFile=[self.selectedFile objectForKey:@"files"];
NSURL*fileUrl=[NSURL URLWithString:videoFile.url];
self.moviePlayer.contentURL=fileUrl;
[self.moviePlayer prepareToPlay];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
I have finished the Ribbit app but the image does not open up, only video.
8 Answers
Stone Preston
42,016 Pointscan you post the prepareForSegue method of your inboxViewController. it should look something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
if ([segue.identifier isEqualToString:@"showImage"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
Stone Preston
42,016 Pointsyes that looks correct. check your storyboard and make sure you have a segue named showImage going from your inbox to your imageViewController.
miles fishman
Courses Plus Student 3,610 Points- (void)viewDidLoad
{
[super viewDidLoad];
PFFile *imageFile =[self.message objectForKey:@"files"];
NSURL*imageFileUrl=[[NSURL alloc]initWithString:imageFile.url];
NSData*imageData=[NSData dataWithContentsOfURL:imageFileUrl];
self.imageView.image=[UIImage imageWithData:imageData];
NSString*senderName=[self.message objectForKey:@"senderName"];
NSString *title=[NSString stringWithFormat:@"Sent from%@",senderName];
self.navigationItem.title=title;
// Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if([self respondsToSelector:@selector(timeout)]){
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timeout) userInfo:nil repeats:NO];
}
else{
NSLog(@"Error:selector missing!");
}
}
-(void)timeout{
[self.navigationController popViewControllerAnimated:YES];
}
miles fishman
Courses Plus Student 3,610 PointsI do this is my error *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter'
Stone Preston
42,016 Pointsare you sure the key name for your file in your message object is named @"files"? it may be named @"file" instead. see what your column is named in parse using the data browser.
miles fishman
Courses Plus Student 3,610 PointsI Just checked, the column with the file inside of it is titled "files"
miles fishman
Courses Plus Student 3,610 Pointsand I still get the error
Stone Preston
42,016 Pointsok log your message object file and the url and see if they have a value:
- (void)viewDidLoad
{
[super viewDidLoad];
PFFile *imageFile =[self.message objectForKey:@"files"];
//check value of imageFile
NSLog(@"imageFile: %@", imageFile);
NSURL*imageFileUrl=[[NSURL alloc]initWithString:imageFile.url];
//check value of the url
NSLog(@"URL: %@", imageFileUrl);
NSData*imageData=[NSData dataWithContentsOfURL:imageFileUrl];
self.imageView.image=[UIImage imageWithData:imageData];
NSString*senderName=[self.message objectForKey:@"senderName"];
NSString *title=[NSString stringWithFormat:@"Sent from%@",senderName];
self.navigationItem.title=title;
// Do any additional setup after loading the view.
}
miles fishman
Courses Plus Student 3,610 Points2014-06-02 07:46:27.630 Ribbit[1485:60b] imageFile: (null) 2014-06-02 07:46:27.633 Ribbit[1485:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initWithString:relativeToURL:]: nil string parameter' I still get the error, but says my imageFile is null, when I checked the data browser on parse after i sent the message , under files there was indeed a file called image.png
miles fishman
Courses Plus Student 3,610 Pointsjust tried again, and it keeps saying its null even though parse is saying it has a file
miles fishman
Courses Plus Student 3,610 PointsI FORGOT TO CAPITALIZE THE I in showImage!!!!!!!
Picture is now working but the bottom bar is hidden and its just white, how do I change that?
miles fishman
Courses Plus Student 3,610 Pointsmiles fishman
Courses Plus Student 3,610 Pointsin my case the property is selectedFile.