Image that i pass from my tableview to detail view does not display when i switch views. Labels and everything else seems to work great. I used to get
2013-08-30 19:53:46.060 iOS[2849:60b] -[PFFile size]: unrecognized selector sent to instance 0x155d7a00
2013-08-30 19:53:46.064 iOS[2849:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFFile size]: unrecognized selector sent to instance 0x155d7a00'
but now it shows no errors but image isn't there.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"detailSegue"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *imageObject = [Booksarray objectAtIndex:indexPath.row];
PFFile *imagefile = [imageObject objectForKey:@"ImageFiles"];
[imagefile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
tempimage= [UIImage imageWithData:data];
}
}];
BookDetailViewController *detailVC = (BookDetailViewController *)segue.destinationViewController;
NSLog(@"Bookarray=%@", Booksarray);
NSLog(@"BookIndex=%@", [Booksarray objectAtIndex:indexPath.row]);
detailVC.Bookname=[[Booksarray objectAtIndex:indexPath.row]objectForKey:@"Books"];
detailVC.BookDescription= [[Booksarray objectAtIndex:indexPath.row]objectForKey:@"BookDetails"];
detailVC.picture=tempimage;
}
}
this is what my detail view looks like
detailview .m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
bookTitle.text=_Bookname;
bookDesc.text=_BookDescription;
BookImage.image=_picture;
[UIImageView load];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
and detailview h.
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface BookDetailViewController : UIViewController <UINavigationControllerDelegate> {
NSArray * images;
}
@property (weak, nonatomic) IBOutlet UIImageView *BookImage;
@property (weak, nonatomic) IBOutlet UILabel *bookTitle;
@property (weak, nonatomic) IBOutlet UILabel *bookDesc;
@property (strong, nonatomic) NSString* Bookname;
@property (strong, nonatomic) NSString* BookDescription;
@property (strong,nonatomic) UIImage * picture;
@end
This code:
[imagefile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error) {
tempimage= [UIImage imageWithData:data];
}
}];
Is an asynchronous download. So, it completes and sets the image into tempimage
after you have used the (empty) variable and the segue has completed.
You should use a PFImageView
and pass it the file and allow it to manage downloading and showing the image for you.