objective c - Specific part of code not being executed in iOS -
i retrieving data parse.com , try add image data array. however, code not being executed without obvious reason. code:
pfquery *userquery = [pfuser query]; [userquery wherekey:@"objectid" containedin:[self.event objectforkey:@"members"]]; [userquery findobjectsinbackgroundwithblock:^(nsarray *users, nserror *error) { if (!error) { self.membersarray = [nsmutablearray arraywitharray:users]; [self.tableview reloaddata]; (pfuser *user in self.membersarray) { [self.memberphotosarray addobject:[nsnull null]]; nsinteger index = [self.memberphotosarray indexofobject:user]; pffile *photofile = [user objectforkey:@"profilepicture"]; [photofile getdatainbackgroundwithblock:^(nsdata *result, nserror *error) { if (!error) { nslog(@"before creating image"); uiimage *image = [uiimage imagewithdata:result]; [self.memberphotosarray[index] addobject:image]; nslog(@"after creating image"); [self.tableview reloaddata]; } }]; } } }]; the first log being executed, after line not being called. can explain why , provide solution?
looks code running on background thread. run code in final callback block on main thread.
if (!error) { nslog(@"before creating image"); uiimage *image = [uiimage imagewithdata:result]; dispatch_async(dispatch_get_main_queue(), ^{ [self.memberphotosarray[index] addobject:image]; nslog(@"after creating image"); [self.tableview reloaddata]; }); } ui related operations should performed on main thread.
Comments
Post a Comment