繁体   English   中英

为什么尝试返回从Parse.com提取的UIImage时出现此错误?

[英]Why do I get this error when trying to return a UIImage fetched from Parse.com?

尝试返回从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覆盖所有基础。 谁能给我一个指示为什么发生这种情况?

因为您不从代码块中返回任何内容。 该代码块将运行,仅此而已,您无需在此返回任何内容。

如果要对该图像进行处理,请在代码块内进行处理。

例如:

[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
        });
    }
}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM