-1

如下日志输出所示,imageFile正确返回,但是image没有

这是segue的代码:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showBandPhoto"]) {
        NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];
        BDBPhotoViewController *destViewController = segue.destinationViewController;
        NSIndexPath *indexPath = [indexPaths objectAtIndex:0];

        PFObject *tempObject = [imageObjectsArray objectAtIndex:indexPath.row];
        NSLog(@"object is %@", tempObject);

        NSString *commentGet = [tempObject objectForKey:@"comment"];
        destViewController.comment = commentGet;

        PFFile *imageFile = [tempObject objectForKey:@"image"];
        NSLog(@"ImageFile is %@", imageFile);
        NSData *data = [imageFile getData];

        UIImage *image = [[UIImage alloc] initWithData:data];
        destViewController.bandImageName = image;

        NSLog(@"image is %@", image);

这是日志输出:

object is Photos:RvKHQNYMtj:(null)
   album = Promos;
    comment = "Promo Pic 2011";
    image = "PFFile: 0x16d901a0";
    ipadImage = "PFFile: 0x16d88f40";
    thumbnail = "PFFile: 0x16d9d360";
ImageFile is PFFile: 0x16d901a0
 Warning: A long-running Parse operation is being executed on the main thread. 
 Break on warnParseOperationOnMainThread() to debug.
 image is UIImage: 0x16ecfac0
 comment is Promo Pic 2011
 image is (null)

感谢您及时的回复。搜索了3个小时,然后发布,10分钟后我发现了我的错误。我没有正确保留财产。

4

1 回答 1

0

根据 initWithData 的文档,如果无法从指定的数据初始化图像,则将返回一个 nil 对象。

您应该检查存储的数据是否实际上是有效图像,或者检查结果[imageFile getData]是否仍然有效数据。

于 2013-10-11T21:56:35.233 回答