簡體   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