2013-10-11 59 views
-1

正如下面的日志输出显示,镜像文件返回正确的,但图像不为什么UIImage变量返回null?

下面是对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分钟后我发现了我的错误。我没有妥善保留财产。

回答

0

根据initWithData的文档将返回一个零对象,如果没有图像可以从指定的数据初始化。

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