Skip to content

Commit

Permalink
* removed bug with wrong index when setting value
Browse files Browse the repository at this point in the history
  • Loading branch information
dlinsin committed Jan 11, 2011
1 parent 371e28f commit 283b313
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions DLStarRating/DLStarRatingControl.m
Expand Up @@ -74,13 +74,21 @@ - (UIButton*)starForPoint:(CGPoint)point {
return nil;
}

- (void)disableStarsDownTo:(int)idx {
- (void)disableStarsDownToExclusive:(int)idx {
for (int i=numberOfStars; i > idx; --i) {
UIButton *b = (UIButton*)[self subViewWithTag:i];
b.highlighted = NO;
}
}

- (void)disableStarsDownTo:(int)idx {
for (int i=numberOfStars; i >= idx; --i) {
UIButton *b = (UIButton*)[self subViewWithTag:i];
b.highlighted = NO;
}
}


- (void)enableStarsUpTo:(int)idx {
for (int i=0; i <= idx; i++) {
UIButton *b = (UIButton*)[self subViewWithTag:i];
Expand All @@ -94,7 +102,7 @@ - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
if (pressedButton) {
int idx = pressedButton.tag;
if (pressedButton.highlighted) {
[self disableStarsDownTo:idx];
[self disableStarsDownToExclusive:idx];
} else {
[self enableStarsUpTo:idx];
}
Expand All @@ -118,7 +126,7 @@ - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
if (idx < currentIdx) {
currentButton.highlighted = NO;
currentIdx = idx;
[self disableStarsDownTo:idx];
[self disableStarsDownToExclusive:idx];
} else if (idx > currentIdx) {
currentButton.highlighted = YES;
pressedButton.highlighted = YES;
Expand All @@ -128,7 +136,7 @@ - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
} else if (point.x < [self subViewWithTag:0].frame.origin.x) {
((UIButton*)[self subViewWithTag:0]).highlighted = NO;
currentIdx = -1;
[self disableStarsDownTo:0];
[self disableStarsDownToExclusive:0];
}
return YES;
}
Expand Down

0 comments on commit 283b313

Please sign in to comment.