Here's the offending code (I believe):
The display shows 3/4 in the middle of the screen as I expect, and upon first touch, the display clears and shows 4/4 at the point touched. But on the 2nd touch, 5/4 appears, but 3/4 reappears. 3rd touch, both 5/4 & 3/4 clear, 6/4 displays, but 4/4 reappears. This pattern continues upon all subsequent touches, (all even numerator show or all odd numerators show.) Strangest of all, when I wait ~10-20 seconds between touches, the old ones will NOT reappear upon the next touch. I fear that this is some kind of timer in the UIKit that I don't know about/understand.
Anyone have any ideas on how to avoid this issue? Is there some clear screen buffer function I'm not aware of?
Thank you.
Code:
@implementation Fraction
-(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
numerator = 3;
denominator = 4;
location = CGPointMake(160, 240);
}
return self;
}
-(void)drawRect:(CGRect)rect {
// Drawing code
NSMutableString *fraction = [NSString stringWithFormat:@"%d/%d", numerator, denominator];
UIFont *font = [UIFont systemFontOfSize:30];
[[UIColor whiteColor] set];
[fraction drawAtPoint:location withFont:font];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// We only support single touches, so anyObject retrieves just that touch from touches
UITouch *touch = [touches anyObject];
numerator = numerator + 1;
location = [touch locationInView:self];
[self setNeedsDisplay];
return;
}
The display shows 3/4 in the middle of the screen as I expect, and upon first touch, the display clears and shows 4/4 at the point touched. But on the 2nd touch, 5/4 appears, but 3/4 reappears. 3rd touch, both 5/4 & 3/4 clear, 6/4 displays, but 4/4 reappears. This pattern continues upon all subsequent touches, (all even numerator show or all odd numerators show.) Strangest of all, when I wait ~10-20 seconds between touches, the old ones will NOT reappear upon the next touch. I fear that this is some kind of timer in the UIKit that I don't know about/understand.
Anyone have any ideas on how to avoid this issue? Is there some clear screen buffer function I'm not aware of?
Thank you.