samedi 1 août 2015

like button with counter in tableview

I have a add UIButton For like in UITableViewcell With UILable for like counter. Now when i click multiple time on button my counter like counts increment/decrement before it’s state transit.also my lable counter shows -1.Please help.

I am using this code in Button action.

 if([code isEqualToString:@"0"])
     {
                 lkcounter =lkcounter+1;

                 [arrOfLikeFlag replaceObjectAtIndex:((UIButton *)sender).tag withObject:@"1"];
                 [arrOFLike replaceObjectAtIndex:((UIButton *)sender).tag withObject:[NSString stringWithFormat:@"%d",lkcounter]];
                 NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:((UIButton *)sender).tag inSection:0];
                 NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, nil];
                 [self.tableView beginUpdates];
                 [HCell.btnlikeoutlate setBackgroundImage:[UIImage imageNamed:@"star_icon1.png"] forState:UIControlStateNormal];
                 [HCell.btnlikeoutlate setUserInteractionEnabled:NO];
                 [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone];
                 [self.tableView endUpdates];
     }
    else
     {
                 lkcounter =lkcounter-1;

                 [arrOfLikeFlag replaceObjectAtIndex:((UIButton *)sender).tag withObject:@"0"];
                 NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:((UIButton *)sender).tag inSection:0];
                 [arrOFLike replaceObjectAtIndex:((UIButton *)sender).tag withObject:[NSString stringWithFormat:@"%d",lkcounter]];
                 NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, nil];
                 [self.tableView beginUpdates];
                 [HCell.btnlikeoutlate setBackgroundImage:[UIImage imageNamed:@"star_icon_selected1.png"] forState:UIControlStateNormal];
                 [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone];
                 [HCell.btnlikeoutlate setUserInteractionEnabled:NO];
                 [self.tableView endUpdates];
     }

Aucun commentaire:

Enregistrer un commentaire