【问题标题】:Why do I get this error when trying to return a UIImage fetched from Parse.com?为什么在尝试返回从 Parse.com 获取的 UIImage 时出现此错误?
【发布时间】:2015-02-23 10:29:53
【问题描述】:

在尝试返回从 Parse.com 获取的 UIImage 以获取以下代码时出现错误:

-(UIImage *)getUserImageForUser:(PFUser *)user {


    PFFile *userImageFile = user[@"profilePic"];
    [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
        if (!error) {
            UIImage *image = [UIImage imageWithData:imageData];
            [self.images setObject:image forKey:user.username];
            return image;

        }
    }];
    return nil;
}

错误是:不兼容的块指针类型将'UIImage *(^)(NSData *__strong, NSError *__strong)'发送到'PFDataResultBlock'类型的参数(又名'void (^)(NSData *__strong, NSError *__strong)')

如果我删除块中的 UIImage 返回,则没有错误。不知道为什么会这样。我通过在最后返回 nil 来覆盖所有基础。谁能告诉我为什么会这样?

【问题讨论】:

    标签: ios objective-c xcode parse-platform


    【解决方案1】:

    因为您不会从代码块中返回任何内容。该代码块运行,就是这样,你不需要在那里返回任何东西。

    如果您想对该图像执行某些操作,请在代码块内执行。

    例如:

    [userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
        if (!error) {
            UIImage *image = [UIImage imageWithData:imageData];
            dispatch_async(dispatch_get_main_queue(), ^{
                // do something with image on the main queue, like: 
                self.imageView.image = image
            });
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-24
      • 2013-03-07
      • 2011-09-19
      • 1970-01-01
      • 2017-01-30
      • 2016-01-03
      • 2012-03-09
      • 2021-05-01
      相关资源
      最近更新 更多