为什么UIImage变量返回null?

时间:2013-10-11 21:17:09

标签: ios uiimage segue

如下面的日志输出所示,imageFile正确返回,但图像不是

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

1 个答案:

答案 0 :(得分:0)

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

您应检查存储的数据是否确实是有效图像,或检查[imageFile getData]的结果是否仍为有效数据。