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
Igal Ben-Dov
2,420 PointsStuck in code
Hello, i'm doing the iOS course, and i'm in the Ribbit app, Build a Self-Destructing Message iPhone App, on the last section.
I have some troubles to run the app, but i cant figure out what is the problem with my code.
This is the part that throw an error. In the first line on PFFile.
- (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];
NSString *senderName = [self.message objectForKey:@"senderName"];
NSString *title = [NSString stringWithFormat:@"Sent by %@", senderName];
self.navigationItem.title = title;
}
Please help me. I'm really stuck on this.
24 Answers
Camilo Castro
Courses Plus Student 2,549 PointsHere's how to fix the Outlet Problem
https://www.dropbox.com/sh/jprcfkps8e1x9iy/AAA26j97Ux1PMrbPvyuqgkiRa
Camilo Castro
Courses Plus Student 2,549 PointsWhat error throws?
Maybe an error related for key without data.
objectForKey looks if the object exists.
Igal Ben-Dov
2,420 PointsThe error is: Ribbit[465:60b] -[UIImageView objectForKey:]: unrecognized selector sent to instance 0x9d54d70.
And this happen when i try to view a image from my inbox.
Igal Ben-Dov
2,420 PointsI have in my Dashboard on Parse.com a object called "file" that hold the images or videos.
Camilo Castro
Courses Plus Student 2,549 PointsYou need to fetch data.
From Parse Docs:
PFFile *userImageFile = anotherPhoto[@"imageFile"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
}
}];
So for this example will be
PFFile *imageFile = [self.message objectForKey:@"file"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.imageView.image = [UIImage imageWithData:imageData];
}
}];
Igal Ben-Dov
2,420 Pointsi used this, but the same error. What i have to modified? Really don't get it. "message" is a PFObject that contains the saved information in Parse, and the column with the images called "file".
<p> PFFile *imageFile = [self.message objectForKey:@"file"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.imageView.image = [UIImage imageWithData:imageData];
}
}];</p>
Camilo Castro
Courses Plus Student 2,549 PointsAre you sure the error is in setting the self.imageView.image property?.
because it says
Ribbit[465:60b] -[UIImageView objectForKey:]: unrecognized selector sent to instance 0x9d54d70.
UIImageView is not a Parse Object so it does not have objectForKey method.
Please check the line 465
Igal Ben-Dov
2,420 PointsNo one of my files have more than 300 lines. Are you sure that number have relation with the lines of code?
The error point to a direction, 0x9d54d70, and this is the direction of the PFObject message
Camilo Castro
Courses Plus Student 2,549 PointsPlease post the entire .h and .m files so I can see where the problem is :)
Igal Ben-Dov
2,420 Points <p>@interface ImageViewController : UIViewController
@property (nonatomic,strong) PFObject *message;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end</p>
```
Igal Ben-Dov
2,420 PointsHow you add a code here??
Camilo Castro
Courses Plus Student 2,549 Pointsuse triple thicks
`
Check the Markdown Cheatsheet below comment textarea :)
Igal Ben-Dov
2,420 Points```@interface ImageViewController : UIViewController
@property (nonatomic,strong) PFObject *message; @property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
Camilo Castro
Courses Plus Student 2,549 PointsOk you .h file seems fine.
PD: strong is the default in iOS 7, so it's optional to write it down.
// It's the same as (nonatomic, strong)
@property(nonatomic) PFObject * message;
Igal Ben-Dov
2,420 Points@interface ImageViewController ()
@end
@implementation ImageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
PFFile *imageFile = [self.message objectForKey:@"file"];
[imageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
self.imageView.image = [UIImage imageWithData:imageData];
}
}];
//PFFile *imageFile = [self.message objectForKey:@"file"];
//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;
}
@end
Camilo Castro
Courses Plus Student 2,549 PointsAll seems quite right in .h and .m maybe the error is in another section of the app.
Please comment all your .m code in viewDidLoad and run the app.
Igal Ben-Dov
2,420 PointsAll works fine if i comment all the .m code in viewDidLoad
Camilo Castro
Courses Plus Student 2,549 PointsYes the code looks fine, maybe you have a problem with the storyboard IBOutlets.
Ben Jakuben
Treehouse TeacherPerhaps self.message isn't being set properly. Can you verify that it has data? How does your prepareForSegue: method look in InboxViewController? Are you setting imageViewController.message like this below?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showLogin"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
else if ([segue.identifier isEqualToString:@"showImage"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
}
Igal Ben-Dov
2,420 PointsYes, I have the same code. I did it with the videos from the classes and i already reviewed many videos, but still cant figure out which is the error.
Ben Jakuben
Treehouse TeacherCan you add a breakpoint on that line where you're setting imageFile? What does self.message look like if you hover over it while debugging? You can also print it in the debug console using "po self.message" (po stands for print object).
Igal Ben-Dov
2,420 Pointsi added the breakpoint. This appear: (ImageViewController *) 0x9c385a0
Camilo Castro
Courses Plus Student 2,549 PointsIt's Probably you are setting something wrong in the prepare for segue
What you got in this method?
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;
Igal Ben-Dov
2,420 PointsCan be possible to send my project file to you?
Igal Ben-Dov
2,420 Pointsif ([segue.identifier isEqualToString:@"showLogIn"]) {
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
else if ([segue.identifier isEqualToString:@"showImage"])
{
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
ImageViewController *imageViewController = (ImageViewController *)segue.destinationViewController;
imageViewController.message = self.selectedMessage;
}
Camilo Castro
Courses Plus Student 2,549 PointsHow do you set the self.selectedMessage property?
Igal Ben-Dov
2,420 Points@property (nonatomic,strong) PFObject *selectedMessage;
Camilo Castro
Courses Plus Student 2,549 Pointswhere do you assign it's value?.
Igal Ben-Dov
2,420 PointsIn this method on InboxViewController class:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedMessage = [self.messages objectAtIndex:indexPath.row];
NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
if ([fileType isEqualToString:@"image"])
{
[self performSegueWithIdentifier:@"showImage" sender:self];
}
else
{
}
}
Camilo Castro
Courses Plus Student 2,549 Pointsif you can upload you project to a dropbox or similar I will see were is the problem.
The code seems all right, but I want to see in action :)
Igal Ben-Dov
2,420 PointsThank you!, give your email to share the folder in dropbox
Camilo Castro
Courses Plus Student 2,549 PointsPlease use share link
Igal Ben-Dov
2,420 PointsCamilo Castro
Courses Plus Student 2,549 PointsAs I though you have problems with your IBOutlets UIImageView was pointing to message rather than imageView property.
Igal Ben-Dov
2,420 Pointshow i fix it ??
Igal Ben-Dov
2,420 Pointsfinally its working fine!!
THANK YOU for all the help and time.
Camilo Castro
Courses Plus Student 2,549 PointsGlad to read that, you are welcome.
please accept my answer so I can get the points :)