Maintaining Shake/SegmentCtrl with Assorted init Colors


#1

If it helps anyone. I ran into the issue during the Chapter 7 silver challenge where, once I had implemented the segmented control, I couldn’t maintain my assorted colors upon init (Bronze Challenge Chapter 6). I also couldn’t maintain turning the circles red on the shake motion, as discussed in Chapter 6. This was because we’re automatically re-running our custom drawRect method. Thus, if we wanna use an array to randomize colors, that was going to happen every time we ran setNeedDisplay. Even if I used my segmented control to setCircleColor to Red, for example, all the circles would still be painted random colors due to our drawRect override.

I circumvented this by creating a BOOL var which I initialized with YES. I then checked for it in our drawRect method, if it was YES, I randomized colors. If it was NO, I used circleColor’s value (set by the shake or segment methods).

Maybe there is a better way to do this, but I figured I’d throw it up here in case anyone else wondered about it.