Like a table counter button
I have an extra UIButton. As in UITableViewcell With UILable for a similar counter. Now when I click on the button multiple times, my counter for example counts the increment / decrement before it transitions state. Also my counter is showing -1. Please, help.
I am using this code in a Button activity.
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];
}
+3
source to share
No one has answered this question yet
Check out similar questions: