ios - AFNetworing - setImageWithURLRequest not working -
i want set tableview cell images in 1 of apps. use afnetworking (1.2.1)
, setimagewithurlrequest
.
my code in set images looks this:
if (user.avatar) { nsstring *imageurl = user.avatar.url; [cell.profileimage setimagewithurlrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:imageurl]] placeholderimage:nil success:^(nsurlrequest *request, nshttpurlresponse *response, uiimage *image) { [cell setneedslayout]; } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error) { nslog(@"error: %@", error); }]; }
my error log returns this:
error: error domain=nsurlerrordomain code=-999 "the operation couldn’t completed. (nsurlerrordomain error -999.)" userinfo=0x1f5b56a0 {nserrorfailingurlkey=https://d2rfichhc2fb9n.cloudfront.net/image/5/cf7t_ba6- nfgl5ah0w4hdvmk_vp7inmioijzmyisimiioijhzg4tdxnlci1hc3nldhmilcjrijoiyxnzzxrzl3vzzxivztivm2mvmja vztizyziwmdawmdawmdawmc5qcgcilcjvijoiin0}
and images dosn't set. didn't have problem before updated afnetworking (1.2.1)
. ideas?
update
tried strip whitespace url this:
nsstring *imageurl = [user.avatar.url stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];
but same error. , maybe dangerous if api sometime contain image file name contains whitespaces.
i see 3 problems:
-999 means
nsurlerrorcancelled
, looksurlrequest
gets cancelled somehow. code of yours? possiblecell
object oruiimageview
profileimage
released prematurely?more recent versions of afnetworking require set image if you're defining success block.
make sure url valid.
try (works when placed in tableview:cellforrowatindexpath:
):
__weak uitableviewcell *weakcell = cell; [cell.imageview setimagewithurlrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:imageurl]] placeholderimage:nil success:^(nsurlrequest *request, nshttpurlresponse *response, uiimage *image) { if (weakcell) { weakcell.imageview.image = image; [weakcell setneedslayout]; } } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error) { nslog(@"error: %@", error); }];
Comments
Post a Comment