objective c - iOS parse black strip on profile picture (PFImageView) -
i using parse backend of app, , seems profile photo not displaying properly, shown in image:
there black strip on john_appleseed's photo.
here code saving profile image:
nsdata *profiledata = uiimagepngrepresentation(cell1.profileview.image); pffile *profilefile = [pffile filewithname:@"profilephoto" data:profiledata]; [profilefile saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (!error) { if (succeeded) { [user setobject:profilefile forkey:@"profilephoto"]; [user saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (!error) { } else { } }]; } } }];
here how retrieve image:(inside pfquerytableviewcontroller)
- (pfquery *)queryfortable { //nslog(@"called"); nsuserdefaults* defaults = [nsuserdefaults standarduserdefaults]; nsstring *filter = [defaults objectforkey:@"topicfilter"]; nslog(@"queryfortable: %@", filter); pfquery *query = [pfquery querywithclassname:@"questions"]; [query includekey:@"user"]; [query wherekey:@"category" equalto:filter]; [query orderbydescending:@"createdat"]; return query; } - (pfobject *)objectatindexpath:(nsindexpath *)indexpath { if (indexpath.section == self.objects.count) { return nil;//this load more cell. } return [self.objects objectatindex:indexpath.section]; }
in - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath object:(pfobject *)object
pfuser *user = [object objectforkey:@"user"]; pfimageview *profileimgview = (pfimageview *)[cell viewwithtag:1]; profileimgview.layer.cornerradius = profileimgview.frame.size.height/2; profileimgview.layer.maskstobounds = yes; pffile *file = user[@"profilephoto"]; profileimgview.file = file; [profileimgview loadinbackground];
any ideas? many thanks.
you should updating user interfaces on main thread. since loading in background, should notify main thread needs update object. loadinbackground
downloading file asynchronously.
here example, can alter needs, illustrate, updating ui components in call has it's benefits; based off of parses own anypic:
nsstring *requesturl = file.url; // save copy of url locally (will not change in block) [file getdatainbackgroundwithblock:^(nsdata *data, nserror *error) { if (!error) { //dispatch on main thread uiimage *image = [uiimage imagewithdata:data]; } else { nslog(@"error on fetching file"); } }];
Comments
Post a Comment