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!
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
maytelabargamalaga
Courses Plus Student 6,465 PointsUITableViewCell: I can not see any images from Parse
#import "listadoProductos.h"
#import "capturaBild.h"
#import "TableViewCell.h"
#import <Parse/Parse.h>
@interface listadoProductos ()
@end
@implementation listadoProductos
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
// [self queryParseMethod];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [_browserImagenes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"imageCell";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSData *imageData =UIImagePNGRepresentation([UIImage imageNamed:@"inbox.png"]);
PFObject *almacen = [_browserImagenes objectAtIndex:indexPath.row];
PFFile *archivo = almacen [@"image"];
[archivo getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
cell.imageView.image = [UIImage imageWithData:imageData];
}
}];
return cell;
}
#pragma mark -Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PFObject *almacen = [_browserImagenes objectAtIndex:indexPath.row];
PFFile *archivo = [almacen objectForKey:@"image"];
[archivo getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
_productList.image = [UIImage imageWithData:data];
}
}];
}
- (void)queryParseMethod {
NSLog(@"start query");
PFQuery *query = [PFQuery queryWithClassName:@"Pedidos"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSArray *browserImagenes= [[NSArray alloc] initWithArray:objects];
NSLog(@"%@", browserImagenes);
[_showPhoto reloadInputViews];
}
}];
}
@end
``
I am try to create a browser images that I have already store in Parse but I can not see any. What could be wrong here?
Thanks in advance
Custom UITableViewCell
import "TableViewCell.h"
import <Parse/Parse.h>
@implementation TableViewCell
@synthesize productList =_productList; @synthesize productName = _productName; @synthesize productPrice = _productPrice;
(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { // Initialization code } return self; }
-
(void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated];
// Configure the view for the selected state }
@end
12 Answers

Derek Saunders
5,167 PointsOkay try this in the recordImage method, you weren't saving the filePath to parse at all which is named archivo, so when you call it in the tableView it can't find it. If this still doesn't work, then maybe you can try going to stackoverflow.com and asking those forums, they are really very helpful I use them all the time.
[archivo saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
} else {
[almacen saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog( @"imagenes almacenadas con exito!!");
[self queryParseMethod];
}
}];
}
}];

maytelabargamalaga
Courses Plus Student 6,465 PointsNO, this is something that get me in a corner. I don't have any idea that could be happend here. I write NSLog and looks that the data is there

Derek Saunders
5,167 PointsTry this in your code in the cellForRowAtIndexPath:
You need to get the URL
PFObject *almacen = [_browserImagenes objectAtIndex:indexPath.row];
PFFile *archivo = [almacen objectForKey:@"image"];
NSURL *imageFileUrl = [[NSURL alloc] initWithString:archivo.url];
NSData *imageData = [NSData dataWithContentsOfFile:imageFileUrl];
cell.imageView.image = [UIImage imageWithData:imageData];

maytelabargamalaga
Courses Plus Student 6,465 PointsCould be wrong that local Id is null. Perhaps for this reason I can not see nothing?

Derek Saunders
5,167 PointsTry creating a new property in the header file @property (nonatomic, strong)NSArray *browserImagenes;
maybe try putting the query objects into the newly created array.
- (void)queryParseMethod {
NSLog(@"start query");
PFQuery *query = [PFQuery queryWithClassName:@"Pedidos"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
self.browserImagenes = objects;
//NSArray *browserImagenes= [[NSArray alloc] initWithArray:objects];
//NSLog(@"%@", browserImagenes);
[_showPhoto reloadInputViews];
}
}];
}
//Then change the PFObject line to this:
PFObject *almacen = [self.browserImagenes objectAtIndex:indexPath.row];

maytelabargamalaga
Courses Plus Student 6,465 PointsDerek, thanks a lot for try to help me. Unfortunately, the code that you wrote is not working. I guess I did something wrong in Parse. need I create a imagePath, perhaps?
Thanks indeed

Derek Saunders
5,167 PointsDo you have the code you used to save the photo to Parse?

maytelabargamalaga
Courses Plus Student 6,465 Points#import "capturaBild.h"
#import <Parse/Parse.h>
@interface capturaBild ()
@end
@implementation capturaBild
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (IBAction)recordImage:(id)sender {
NSData *imageData =UIImagePNGRepresentation([UIImage imageNamed:@"inbox.png"]);
PFFile *archivo = [PFFile fileWithName:@"inbox.png" data:imageData];
PFObject *almacen = [PFObject objectWithClassName:@"Pedidos"];
[almacen setObject:archivo forKey:@"imageFile"];
almacen [@"image"]=@"camera.png";
almacen [@"imageNombre"]= @"Mayte";
almacen [@"ruta"]= @"UIImagePickerControllerSourceTypeCamera";
[almacen saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog( @"imagenes almacenadas con exito!!");
[self queryParseMethod];
}
}];
}
- (void)queryParseMethod {
NSLog(@"start query");
PFQuery *query = [PFQuery queryWithClassName:@"collectionViewData"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
NSArray *browserImagenes= [[NSArray alloc] initWithArray:objects];
NSLog(@"%@", browserImagenes);
[_showPhoto reloadInputViews];
}
}];
}
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *captura =[[UIImagePickerController alloc]init];
captura.delegate = self;
[captura setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:captura animated:YES completion:NULL];
[captura reloadInputViews];
}
- (IBAction)chooseExisting:(id)sender {
UIImagePickerController *libreria =[[UIImagePickerController alloc]init];
libreria.delegate =self;
[libreria setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:libreria animated:YES completion:NULL];
[libreria reloadInputViews];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSArray *browserImagenes = [info objectForKey:UIImagePickerControllerOriginalImage];
[_showPhoto setImage:browserImagenes];
[self dismissViewControllerAnimated:YES completion:NULL];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
@end

maytelabargamalaga
Courses Plus Student 6,465 PointsHere is the code that I used to create a class and image in Parse

Derek Saunders
5,167 PointsOkay I will look at it, everything is saving to Parse okay right?

maytelabargamalaga
Courses Plus Student 6,465 PointsYes. But I am not sure about imagePath or URL that you asked me before.

maytelabargamalaga
Courses Plus Student 6,465 PointsDerek, thank you for email at the end I can not solve my problem but I will try in stackoverflow like you told.
Thanks indeed

obey me
1,135 PointsDerek Saunders i kinda have the same problem did you figure it out

maytelabargamalaga
Courses Plus Student 6,465 PointsDerek, thanks so much for try to help me. I really really appreciate it. So, I did not see what did you tell me. kinda? How I can find this link?
Thanks indeed.

obey me
1,135 Pointslol i fix the problem

Derek Saunders
5,167 PointsHi Mayte, sorry to see you are still trying to figure this out. Go to http://www.stackoverflow.com and create an account and it's a huge community with tons of programmers willing to help in a matter of minutes.

maytelabargamalaga
Courses Plus Student 6,465 PointsObey. Thanks for information. Could you so kind to share the code, please? or just review my code and give me some advice about it.
Thanks a lot!!

maytelabargamalaga
Courses Plus Student 6,465 PointsHi. Derek. Thank you for your email and your advice. In fact, I am in stackoverflow.com since a couple of months when I started with Objective-C. And once, I resolved my problem but most of the time I did not receive an answer. So for this reason, I prefer to write here because most of the time you have an answer. (although I always write in stackoverflow looking for an answer.
Thanks a lot for your interest!!!
Derek Saunders
5,167 PointsDerek Saunders
5,167 PointsDoes it give you an error at all?