图片无法加载?

时间:2014-03-21 23:54:09

标签: ios uiimageview uiimage parse-platform uistoryboardsegue

当我切换视图时,我从tableview传递到详细视图的图像不会显示。标签和其他一切看起来都很棒。我曾经得到

  

2013-08-30 19:53:46.0​​60 iOS [2849:60b] - [PFFile size]:无法识别的选择器发送到实例0x155d7a00

     

2013-08-30 19:53:46.0​​64 iOS [2849:60b] * 由于未捕获的异常'NSInvalidArgumentException'而终止应用,原因:' - [PFFile size]:无法识别的选择器发送到实例0x155d7a00'

但现在它没有显示错误,但图像不存在。

   - (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

1 个答案:

答案 0 :(得分:1)

此代码:

[imagefile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
     if (!error) {
         tempimage= [UIImage imageWithData:data];
     }
}];

是异步下载。因此,在使用(空)变量并完成segue后,它会完成并将图像设置为tempimage

您应该使用PFImageView并将其传递给该文件,并允许其管理下载并为您显示图像。