objective c - Parse loading Image into UIImageView iOS -


here code data passing on scene image:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     [super tableview:tableview didselectrowatindexpath:indexpath];     rowno = indexpath.row;     pfuser *currentuser = [pfuser currentuser];     pfquery *query = [pfquery querywithclassname:@"photo"];     [query wherekey:@"username" equalto:currentuser.username];     [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {         _photo = [objects objectatindex:rowno];     }];      [self performseguewithidentifier:@"showimagecloseup" sender:self];  }  -(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender{     imagecloseupviewcontroller *destination = [segue destinationviewcontroller];     destination.photoobject = _photo; } 

and here code loads image:

- (void)viewdidload {     [super viewdidload];     pffile *p = [_photoobject objectforkey:@"photo"];    [p getdatainbackgroundwithblock:^(nsdata *data, nserror *error) {        if(!error){            uiimage *image = [uiimage imagewithdata:data];            [_imageview setimage:image];        }    }]; 

for reason, image not loading, why so? how can fix it?

this:

[query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {     _photo = [objects objectatindex:rowno]; }];  [self performseguewithidentifier:@"showimagecloseup" sender:self]; 

needs be:

[query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {     _photo = [objects objectatindex:rowno];     [self performseguewithidentifier:@"showimagecloseup" sender:self]; }]; 

because:

// runs 1st - executes in background thread stores block, runs block once it's done [query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {     // runs 3rd - segued @ point     _photo = [objects objectatindex:rowno]; }];  // runs 2nd - starts segue [self performseguewithidentifier:@"showimagecloseup" sender:self]; 

however, seems there's overall problem design pattern. if have access objects, shouldn't have requery entire database each time. have reference array populating tableview? if so, this:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     [super tableview:tableview didselectrowatindexpath:indexpath];     rowno = indexpath.row;     _photo = yourdataarray[indexpath.row];     [self performseguewithidentifier:@"showimagecloseup" sender:self];  } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -