[self setNeedsDisplay] in (void)MotionBegan vs (void)setCirc


#1

…run out of space int he topic title. Anyways, wondering why do I need to write a separate method to send the setNeedsDisplay instead of just adding it to (void)motionBegan? This refers to page 136/137 in the book.

If I do something like this

[code]//detect shake and if shake occured change color to red

  • (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    NSLog(@“Device started shaking!”);
    [self setCircleColor:[UIColor redColor]];
    [self setNeedsDisplay];
    }[/code]

is works just fine and the circle color changes to red upon device shake.

Instead the authors suggest to

[code]//detect shake and if shake occured change color to red

  • (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {
    NSLog(@“Device started shaking!”);
    [self setCircleColor:[UIColor redColor]];
    }

  • (void)setCircleColor:(UIColor *)clr;
    {
    circleColor = clr;
    [self setNeedsDisplay];
    }
    [/code]

Why?