objective c - iOS Parse Query - Percentage Logging Different Numbers -


i'm returning 2 different queries parse...1 likecount , 1 dislikecount. when query each , set them equal respective labels come out correct. trying percentage of likes dividing likecount likecount+dislikecount.

the query run when button pressed , push segue initialized. logs correct numbers (usually first time). however, after first time query run , 1 or maybe both of numbers values don't update , outputs labels initial text.

@property (nonatomic, assign) float likecount; @property (nonatomic, assign) float dislikecount;   - (void)queryforuseractivity {     //create array check either user photo     nsarray *userphotos = @[self.firstuserphoto, self.seconduserphoto];      pfquery *queryforlikes = [pfquery querywithclassname:kddactivityclasskey];     [queryforlikes wherekey:kddactivitytypekey equalto:kddactivitytypelikekey];     [queryforlikes wherekey:kddactivityfirstuserphotokey containedin:userphotos];     [queryforlikes wherekey:kddactivityseconduserphotokey containedin:userphotos];     [queryforlikes countobjectsinbackgroundwithblock:^(int number, nserror *error) {         self.totallikeslabel.text = [nsstring stringwithformat:@"%i", number];     }];      pfquery *queryfordislikes = [pfquery querywithclassname:kddactivityclasskey];     [queryfordislikes wherekey:kddactivitytypekey equalto:kddactivitytypedislikekey];     [queryfordislikes wherekey:kddactivityfirstuserphotokey containedin:userphotos];     [queryfordislikes wherekey:kddactivityseconduserphotokey containedin:userphotos];     [queryfordislikes countobjectsinbackgroundwithblock:^(int number, nserror *error) {         self.totaldislikeslabel.text = [nsstring stringwithformat:@"%i", number];     }];      pfquery *queryforapprovalpercent = [pfquery orquerywithsubqueries:@[queryforlikes, queryfordislikes]];     [queryforapprovalpercent countobjectsinbackgroundwithblock:^(int number, nserror *error) {         if (!error) {             self.likecount = [self.totallikeslabel.text floatvalue];             self.dislikecount = [self.totaldislikeslabel.text floatvalue];             nslog(@"%f", self.likecount);             nslog(@"%f", self.dislikecount);             float approvalpercentage = (self.likecount / (self.likecount + self.dislikecount)) * 100.0;             self.approvalpercentagelabel.text = [nsstring stringwithformat:@"%2.0f%%", approvalpercentage];             if (approvalpercentage < 5) self.approvalpercentagelabel.textcolor = [uicolor redcolor];         }     }]; } 


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -